Skip to content

Commit 4003920

Browse files
committed
Global usage of the same singleton and test fixes
1 parent 42da19f commit 4003920

4 files changed

Lines changed: 5 additions & 19 deletions

File tree

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import Vue from 'vue';
21
// the new home for analytics
32
import { Analytics } from 'shared/composables/useAnalytics';
43

54
/**
65
* @param Vue
7-
* @param {Object} options
8-
* @param {Array} options.dataLayer
96
*/
10-
export default function AnalyticsPlugin(Vue, options = {}) {
11-
const analytics = new Analytics(options.dataLayer);
12-
13-
// Merge in old dataLayer
14-
if (Vue.$analytics) {
15-
analytics.dataLayer.push(...Vue.$analytics.dataLayer);
16-
Vue.$analytics.destroy();
17-
}
7+
export default function AnalyticsPlugin(Vue) {
8+
const analytics = Analytics.getInstance();
189

1910
Vue.$analytics = analytics;
2011
Vue.mixin({
@@ -24,6 +15,3 @@ export default function AnalyticsPlugin(Vue, options = {}) {
2415
},
2516
});
2617
}
27-
28-
// Initialize with empty dataLayer
29-
AnalyticsPlugin(Vue, { dataLayer: [] });

contentcuration/contentcuration/frontend/shared/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Vue.use(Vuetify, {
252252
Vue.use(KThemePlugin);
253253

254254
// Register analytics plugin with dataLayer that should already be defined
255-
Vue.use(AnalyticsPlugin, { dataLayer: window.dataLayer });
255+
Vue.use(AnalyticsPlugin);
256256

257257
// Register global components
258258
Vue.component('ActionLink', ActionLink);

contentcuration/contentcuration/frontend/shared/composables/__tests__/useAnalytics.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('useAnalytics', () => {
77
beforeEach(() => {
88
// Reset modules to get fresh composable instance
99
jest.resetModules();
10+
Analytics.destroyInstance();
1011

1112
// Create mock dataLayer
1213
mockDataLayer = [];
@@ -28,7 +29,6 @@ describe('useAnalytics', () => {
2829

2930
afterEach(() => {
3031
jest.restoreAllMocks();
31-
Analytics.destroyInstance();
3232
resetIntervals = 0;
3333
});
3434

jest_config/setup.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ Vue.use(Vuetify, {
5252
});
5353
// Register kolibri-design-system plugin
5454
Vue.use(KThemePlugin);
55-
56-
// Register analytics plugin with plain array
57-
Vue.use(AnalyticsPlugin, { dataLayer: [] });
55+
Vue.use(AnalyticsPlugin);
5856

5957
// Register global components
6058
Vue.component('ActionLink', ActionLink);

0 commit comments

Comments
 (0)