From c7e8ed55970b41982b9ae2d3729c388794e42800 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Mon, 12 Feb 2024 15:24:33 +0100 Subject: [PATCH 01/10] ga4-params Send correct(ly prefixed) params to the GA4 script --- .../src/GoogleAnalytics4.js | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js index 85576211..9f2ec4d5 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.js @@ -8,7 +8,11 @@ const GTAG_ROOT_VARIABLE = 'gtag'; export default class GoogleAnalytics4 extends AbstractAnalytic { /** @type {import('@ima/core').Dependencies} */ static get $dependencies() { - return [...defaultDependencies, '$Settings.plugin.analytic.google4']; + return [ + ...defaultDependencies, + '$Settings.plugin.analytic.google4', + '$Router', + ]; } set _ga4Script(value) { @@ -29,9 +33,10 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * @param {import('@ima/plugin-script-loader').ScriptLoaderPlugin} scriptLoader * @param {import('@ima/core').Window} window * @param {import('@ima/core').Dispatcher} dispatcher - * @param {Object} config + * @param {{[key: string]: *}} config + * @param {import('@ima/core').Router} router */ - constructor(scriptLoader, window, dispatcher, config) { + constructor(scriptLoader, window, dispatcher, config, router) { super(scriptLoader, window, dispatcher, config); this._analyticScriptName = 'google_analytics_4'; @@ -39,12 +44,20 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { this._analyticScriptUrl = `https://www.googletagmanager.com/gtag/js?id=${this._config.service}`; this._consentSettings = this._config.consentSettings; + + this._router = router; + + /** + * Stores page location to serve as next page hit's referrer + * to compensate for SPA browsing. + */ + this._referrer = ''; } /** * Hits custom event of given with given data * * @param {string} eventName custom event name - * @param {Object} eventData custom event data + * @param {{[key: string]: *}} eventData custom event data */ hit(eventName, eventData) { if (!this.isEnabled()) { @@ -58,8 +71,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * Hit page view event to analytic with defined data. * * @override - * @param {Object} pageData - * @param {Object} customDimensions + * @param {{[key: string]: *}} pageData */ hitPageView(pageData) { if (!this.isEnabled()) { @@ -72,7 +84,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { /** * Updates user consents in Google Analytics script * - * @param {Object} purposeConsents Purpose Consents of TCModel, see: https://www.npmjs.com/package/@iabtcf/core#tcmodel + * @param {{[key: string]: *}} purposeConsents Purpose Consents of TCModel, see: https://www.npmjs.com/package/@iabtcf/core#tcmodel */ updateConsent(purposeConsents) { this._applyPurposeConsents(purposeConsents); @@ -126,14 +138,21 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { /** * Returns page view data derived from pageData param. * - * @param {Object} pageData - * @returns {Object} pageViewData + * @param {{[key: string]: *}} pageData + * @returns {{[key: string]: *}} pageViewData */ _getPageViewData(pageData) { + const page_location = this._window.getUrl(); + const page_referrer = this._referrer || this._window.getDocument().referrer; + this._referrer = page_location; + return { - page: pageData.path, - location: this._window.getUrl(), - title: document.title || '', + page_path: pageData.path, + page_location, + page_referrer, + page_route: this?._router?.getCurrentRouteInfo()?.route?.getName() || '', + page_status: '', // WIP + page_title: document.title || '', }; } From 6bc0f952a4054bfd0358d8eb5f6989056c566673 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Mon, 12 Feb 2024 15:24:53 +0100 Subject: [PATCH 02/10] ga4-params Add missing consent settings --- packages/plugin-analytic-google/src/main.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/plugin-analytic-google/src/main.ts b/packages/plugin-analytic-google/src/main.ts index d799e7d4..e5a7ef4f 100644 --- a/packages/plugin-analytic-google/src/main.ts +++ b/packages/plugin-analytic-google/src/main.ts @@ -38,7 +38,10 @@ pluginLoader.register('@ima/plugin-analytic-google', () => ({ consentSettings: { ad_storage: 'denied', analytics_storage: 'denied', + functionality_storage: 'denied', personalization_storage: 'denied', + security_storage: 'denied', + ad_user_data: 'denied', }, service: 'G-XXXXXXXXXX', waitForUpdateTimeout: 5000, From f9ed09442032c7a0965d2fc26e9f0b518ae1b4eb Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Mon, 12 Feb 2024 16:35:34 +0100 Subject: [PATCH 03/10] ga4-params Use `route` directly from `pageData` --- .../src/GoogleAnalytics4.js | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js index 9f2ec4d5..cb4ab30a 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.js @@ -8,11 +8,7 @@ const GTAG_ROOT_VARIABLE = 'gtag'; export default class GoogleAnalytics4 extends AbstractAnalytic { /** @type {import('@ima/core').Dependencies} */ static get $dependencies() { - return [ - ...defaultDependencies, - '$Settings.plugin.analytic.google4', - '$Router', - ]; + return [...defaultDependencies, '$Settings.plugin.analytic.google4']; } set _ga4Script(value) { @@ -33,10 +29,9 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * @param {import('@ima/plugin-script-loader').ScriptLoaderPlugin} scriptLoader * @param {import('@ima/core').Window} window * @param {import('@ima/core').Dispatcher} dispatcher - * @param {{[key: string]: *}} config - * @param {import('@ima/core').Router} router + * @param {Object} config */ - constructor(scriptLoader, window, dispatcher, config, router) { + constructor(scriptLoader, window, dispatcher, config) { super(scriptLoader, window, dispatcher, config); this._analyticScriptName = 'google_analytics_4'; @@ -45,8 +40,6 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { this._consentSettings = this._config.consentSettings; - this._router = router; - /** * Stores page location to serve as next page hit's referrer * to compensate for SPA browsing. @@ -57,7 +50,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * Hits custom event of given with given data * * @param {string} eventName custom event name - * @param {{[key: string]: *}} eventData custom event data + * @param {Object} eventData custom event data */ hit(eventName, eventData) { if (!this.isEnabled()) { @@ -71,7 +64,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * Hit page view event to analytic with defined data. * * @override - * @param {{[key: string]: *}} pageData + * @param {Object} pageData */ hitPageView(pageData) { if (!this.isEnabled()) { @@ -84,7 +77,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { /** * Updates user consents in Google Analytics script * - * @param {{[key: string]: *}} purposeConsents Purpose Consents of TCModel, see: https://www.npmjs.com/package/@iabtcf/core#tcmodel + * @param {Object} purposeConsents Purpose Consents of TCModel, see: https://www.npmjs.com/package/@iabtcf/core#tcmodel */ updateConsent(purposeConsents) { this._applyPurposeConsents(purposeConsents); @@ -138,8 +131,8 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { /** * Returns page view data derived from pageData param. * - * @param {{[key: string]: *}} pageData - * @returns {{[key: string]: *}} pageViewData + * @param {Object} pageData + * @returns {Object} pageViewData */ _getPageViewData(pageData) { const page_location = this._window.getUrl(); @@ -150,8 +143,8 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { page_path: pageData.path, page_location, page_referrer, - page_route: this?._router?.getCurrentRouteInfo()?.route?.getName() || '', - page_status: '', // WIP + page_route: pageData?.route?.getName() || '', + page_status: pageData?.response?.status, page_title: document.title || '', }; } From bdfbc9f69bae237e9e19e124cbed10bd24a2882c Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Tue, 20 Feb 2024 17:09:55 +0100 Subject: [PATCH 04/10] ga4-params Set `this._referrer` when page hit is sent, not when processing data --- packages/plugin-analytic-google/src/GoogleAnalytics4.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js index cb4ab30a..27a981f2 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.js @@ -70,8 +70,9 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { if (!this.isEnabled()) { return; } - - this._ga4Script('event', 'page_view', this._getPageViewData(pageData)); + const pageViewData = this._getPageViewData(pageData); + this._ga4Script('event', 'page_view', pageViewData); + this._referrer = pageViewData.page_location; } /** @@ -137,7 +138,6 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { _getPageViewData(pageData) { const page_location = this._window.getUrl(); const page_referrer = this._referrer || this._window.getDocument().referrer; - this._referrer = page_location; return { page_path: pageData.path, From 4d3a579ac3e3648a0a6f5326419e738d9f5c22f4 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Wed, 13 Mar 2024 13:22:27 +0100 Subject: [PATCH 05/10] ga4-params Add changeset --- .changeset/clever-seals-pull.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/clever-seals-pull.md diff --git a/.changeset/clever-seals-pull.md b/.changeset/clever-seals-pull.md new file mode 100644 index 00000000..d3854b62 --- /dev/null +++ b/.changeset/clever-seals-pull.md @@ -0,0 +1,9 @@ +--- +"@ima/plugin-analytic-google": major +--- + +Update data sent in a GA4 page view hit + +**What:** Add the prefix `page_` to the existing params (these are the correct default names for GA4) and add new parameters. Save `referrer` to correspond to the actual referrer in SPA browsing. Add missing consent settings. +**Why:** We were hitting page view incorrectly. +**How:** Nothing. From b696c8c734e5562fabf636cc6a064729924ab574 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Wed, 13 Mar 2024 13:57:36 +0100 Subject: [PATCH 06/10] ga4-params Fix tests --- .../src/GoogleAnalytics4.js | 3 +- .../src/__tests__/GoogleAnalytics4Spec.js | 58 +++++++++++++------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js index 27a981f2..0b3e7497 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.js @@ -137,7 +137,8 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { */ _getPageViewData(pageData) { const page_location = this._window.getUrl(); - const page_referrer = this._referrer || this._window.getDocument().referrer; + const page_referrer = + this._referrer || this._window?.getDocument()?.referrer; return { page_path: pageData.path, diff --git a/packages/plugin-analytic-google/src/__tests__/GoogleAnalytics4Spec.js b/packages/plugin-analytic-google/src/__tests__/GoogleAnalytics4Spec.js index 0627ac07..ebec4246 100644 --- a/packages/plugin-analytic-google/src/__tests__/GoogleAnalytics4Spec.js +++ b/packages/plugin-analytic-google/src/__tests__/GoogleAnalytics4Spec.js @@ -10,24 +10,37 @@ describe('GoogleAnalytics4', () => { consentSettings: {}, }; - const mockGtag = { + let mockDocument; + + function setMockDocument(document = {}) { + mockDocument = { ...document }; + global.document = mockDocument; + } + + const mockWindow = { gtag: jest.fn(), }; const mockUrl = 'mockUrl'; const scriptLoader = toMockedInstance(ScriptLoaderPlugin); const dispatcher = toMockedInstance(Dispatcher); - const window = toMockedInstance(Window, { - getWindow() { - return mockGtag; - }, - getUrl() { - return mockUrl; - }, - }); + let googleAnalytics4 = null; beforeEach(() => { + setMockDocument(); + const window = toMockedInstance(Window, { + getDocument() { + return mockDocument; + }, + getWindow() { + return mockWindow; + }, + getUrl() { + return mockUrl; + }, + }); + googleAnalytics4 = new GoogleAnalytics4( scriptLoader, window, @@ -47,17 +60,26 @@ describe('GoogleAnalytics4', () => { const pageTitle = 'Page title'; const mockPath = 'somePath'; + const mockReferrer = 'https://google.com'; - global.document = { + setMockDocument({ title: pageTitle, - }; + referrer: mockReferrer, + }); - googleAnalytics4.hitPageView({ path: mockPath }); + googleAnalytics4.hitPageView({ + path: mockPath, + response: { status: 200 }, + route: { getName: () => 'someRoute' }, + }); - expect(mockGtag.gtag).toHaveBeenCalledWith('event', 'page_view', { - location: mockUrl, - page: mockPath, - title: pageTitle, + expect(mockWindow.gtag).toHaveBeenCalledWith('event', 'page_view', { + page_location: mockUrl, + page_path: mockPath, + page_title: pageTitle, + page_referrer: mockReferrer, + page_route: 'someRoute', + page_status: 200, }); }); }); @@ -74,7 +96,7 @@ describe('GoogleAnalytics4', () => { googleAnalytics4.hit(customEventName, customEventData); - expect(mockGtag.gtag).toHaveBeenCalledWith( + expect(mockWindow.gtag).toHaveBeenCalledWith( 'event', customEventName, customEventData @@ -116,7 +138,7 @@ describe('GoogleAnalytics4', () => { googleAnalytics4.updateConsent(purposeConsents); - expect(mockGtag.gtag).toHaveBeenCalledWith( + expect(mockWindow.gtag).toHaveBeenCalledWith( 'consent', 'update', expect.any(Object) From 27d17b21630f82dd44f07407d3bb0ad153e954fd Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Fri, 15 Mar 2024 12:14:02 +0100 Subject: [PATCH 07/10] ga4-params Consistently use window and document through IMA `Window` class --- .../plugin-analytic-google/src/GoogleAnalytics4.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js index 0b3e7497..86b23485 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.js @@ -137,8 +137,8 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { */ _getPageViewData(pageData) { const page_location = this._window.getUrl(); - const page_referrer = - this._referrer || this._window?.getDocument()?.referrer; + const clientDocument = this._window?.getDocument(); + const page_referrer = this._referrer || clientDocument?.referrer; return { page_path: pageData.path, @@ -146,7 +146,7 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { page_referrer, page_route: pageData?.route?.getName() || '', page_status: pageData?.response?.status, - page_title: document.title || '', + page_title: clientDocument.title || '', }; } @@ -155,12 +155,12 @@ export default class GoogleAnalytics4 extends AbstractAnalytic { * @inheritdoc */ _createGlobalDefinition() { - const window = this._window.getWindow(); + const clientWindow = this._window.getWindow(); - window.dataLayer = window.dataLayer || []; + clientWindow.dataLayer = clientWindow.dataLayer || []; this._ga4Script = function () { - window.dataLayer.push(arguments); + clientWindow.dataLayer.push(arguments); }; this._configuration(); From c69c207f45bc14992024253fe958502e3ea2156c Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Mon, 8 Apr 2024 15:22:58 +0200 Subject: [PATCH 08/10] ga4-params Move new code to TS file version --- .../src/GoogleAnalytics4.js | 168 ------------------ .../src/GoogleAnalytics4.ts | 21 ++- 2 files changed, 17 insertions(+), 172 deletions(-) delete mode 100644 packages/plugin-analytic-google/src/GoogleAnalytics4.js diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.js b/packages/plugin-analytic-google/src/GoogleAnalytics4.js deleted file mode 100644 index 86b23485..00000000 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.js +++ /dev/null @@ -1,168 +0,0 @@ -import { AbstractAnalytic, defaultDependencies } from '@ima/plugin-analytic'; - -const GTAG_ROOT_VARIABLE = 'gtag'; - -/** - * Google analytic 4 class - */ -export default class GoogleAnalytics4 extends AbstractAnalytic { - /** @type {import('@ima/core').Dependencies} */ - static get $dependencies() { - return [...defaultDependencies, '$Settings.plugin.analytic.google4']; - } - - set _ga4Script(value) { - const clientWindow = this._window.getWindow(); - - clientWindow[GTAG_ROOT_VARIABLE] = value; - } - - get _ga4Script() { - const clientWindow = this._window.getWindow(); - - return clientWindow[GTAG_ROOT_VARIABLE]; - } - - /** - * Initializes the Google Analytics 4 plugin. - * - * @param {import('@ima/plugin-script-loader').ScriptLoaderPlugin} scriptLoader - * @param {import('@ima/core').Window} window - * @param {import('@ima/core').Dispatcher} dispatcher - * @param {Object} config - */ - constructor(scriptLoader, window, dispatcher, config) { - super(scriptLoader, window, dispatcher, config); - - this._analyticScriptName = 'google_analytics_4'; - - this._analyticScriptUrl = `https://www.googletagmanager.com/gtag/js?id=${this._config.service}`; - - this._consentSettings = this._config.consentSettings; - - /** - * Stores page location to serve as next page hit's referrer - * to compensate for SPA browsing. - */ - this._referrer = ''; - } - /** - * Hits custom event of given with given data - * - * @param {string} eventName custom event name - * @param {Object} eventData custom event data - */ - hit(eventName, eventData) { - if (!this.isEnabled()) { - return; - } - - this._ga4Script('event', eventName, eventData); - } - - /** - * Hit page view event to analytic with defined data. - * - * @override - * @param {Object} pageData - */ - hitPageView(pageData) { - if (!this.isEnabled()) { - return; - } - const pageViewData = this._getPageViewData(pageData); - this._ga4Script('event', 'page_view', pageViewData); - this._referrer = pageViewData.page_location; - } - - /** - * Updates user consents in Google Analytics script - * - * @param {Object} purposeConsents Purpose Consents of TCModel, see: https://www.npmjs.com/package/@iabtcf/core#tcmodel - */ - updateConsent(purposeConsents) { - this._applyPurposeConsents(purposeConsents); - - this._ga4Script('consent', 'update', { - ...this._consentSettings, - }); - } - - /** - * @override - * @inheritdoc - */ - _applyPurposeConsents(purposeConsents) { - if (purposeConsents && typeof purposeConsents === 'object') { - if (purposeConsents['1']) { - this._consentSettings.analytics_storage = 'granted'; - } else { - this._consentSettings.analytics_storage = 'denied'; - } - } - } - - /** - * @override - * @inheritdoc - */ - _configuration() { - if ( - this.isEnabled() || - !this._ga4Script || - typeof this._ga4Script !== 'function' - ) { - return; - } - - this._enable = true; - - this._ga4Script('consent', 'default', { - ...this._consentSettings, - wait_for_update: this._config.waitForUpdateTimeout, - }); - - this._ga4Script('js', new Date()); - - this._ga4Script('config', this._config.service, { - send_page_view: false, - }); - } - - /** - * Returns page view data derived from pageData param. - * - * @param {Object} pageData - * @returns {Object} pageViewData - */ - _getPageViewData(pageData) { - const page_location = this._window.getUrl(); - const clientDocument = this._window?.getDocument(); - const page_referrer = this._referrer || clientDocument?.referrer; - - return { - page_path: pageData.path, - page_location, - page_referrer, - page_route: pageData?.route?.getName() || '', - page_status: pageData?.response?.status, - page_title: clientDocument.title || '', - }; - } - - /** - * @override - * @inheritdoc - */ - _createGlobalDefinition() { - const clientWindow = this._window.getWindow(); - - clientWindow.dataLayer = clientWindow.dataLayer || []; - - this._ga4Script = function () { - clientWindow.dataLayer.push(arguments); - }; - - this._configuration(); - } -} diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts index ff6e26b1..63eb58df 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts @@ -20,6 +20,7 @@ export type AnalyticGoogleSettings = { */ export class GoogleAnalytics4 extends AbstractAnalytic { #config: AnalyticGoogleSettings; + #referrer: string; _consentSettings?: ConsentSettings; static get $dependencies(): Dependencies { @@ -47,6 +48,8 @@ export class GoogleAnalytics4 extends AbstractAnalytic { /** * Initializes the Google Analytics 4 plugin. + * @param config + * @param {...any} rest */ constructor( config: AnalyticGoogleSettings, @@ -55,6 +58,7 @@ export class GoogleAnalytics4 extends AbstractAnalytic { super(...rest); this.#config = config; + this.#referrer = ''; this._analyticScriptName = 'google_analytics_4'; @@ -85,7 +89,9 @@ export class GoogleAnalytics4 extends AbstractAnalytic { return; } - this._ga4Script('event', 'page_view', this._getPageViewData(pageData)); + const pageViewData = this._getPageViewData(pageData); + this._ga4Script('event', 'page_view', pageViewData); + this.#referrer = pageViewData.page_location; } /** @@ -150,10 +156,17 @@ export class GoogleAnalytics4 extends AbstractAnalytic { * Returns page view data derived from pageData param. */ _getPageViewData(pageData: Record) { + const page_location = this._window.getUrl(); + const clientDocument = this._window?.getDocument(); + const page_referrer = this.#referrer || clientDocument?.referrer; + return { - page: pageData.path, - location: this._window.getUrl(), - title: document.title || '', + page_path: pageData.path, + page_location, + page_referrer, + page_route: pageData?.route?.getName() || '', + page_status: pageData?.response?.status, + page_title: clientDocument?.title || '', }; } From 3b2f68ef31418abc5aa596b60a4c1a2c64217bb9 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Thu, 11 Apr 2024 09:57:57 +0200 Subject: [PATCH 09/10] ga4-params Pull request fix --- package-lock.json | 8 ++++---- package.json | 2 +- packages/plugin-analytic-google/src/GoogleAnalytics4.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0a188507..88e3e91a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "@babel/preset-react": "^7.22.3", "@cfaester/enzyme-adapter-react-18": "^0.7.0", "@changesets/cli": "^2.26.1", - "@ima/plugin-cli": "^19.1.1", + "@ima/plugin-cli": "^19.1.2", "@swc/jest": "^0.2.26", "@types/jest": "^29.5.1", "@types/node": "^20.2.5", @@ -2587,9 +2587,9 @@ "link": true }, "node_modules/@ima/plugin-cli": { - "version": "19.1.1", - "resolved": "https://registry.npmjs.org/@ima/plugin-cli/-/plugin-cli-19.1.1.tgz", - "integrity": "sha512-VYjkF9+Hm+RXEkPiaRdBbu5kY4xDSyuzr4hnAC4hY7O5pVoJNBZIU0Fcm20lO8pbthlYZ4b/Rl7vDwLqplSVVA==", + "version": "19.1.2", + "resolved": "https://registry.npmjs.org/@ima/plugin-cli/-/plugin-cli-19.1.2.tgz", + "integrity": "sha512-uU97ZipyhTVCx1JgQhNUCUyd+MdwBOFlDI/MP837c/XmIFOZGDFRV9mEqoWnXcxAw79RmhNHlW9xquUdbFZX7g==", "dev": true, "dependencies": { "@ima/dev-utils": "^19.0.0", diff --git a/package.json b/package.json index 232f2206..df382b9c 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@babel/preset-react": "^7.22.3", "@cfaester/enzyme-adapter-react-18": "^0.7.0", "@changesets/cli": "^2.26.1", - "@ima/plugin-cli": "^19.1.1", + "@ima/plugin-cli": "^19.1.2", "@swc/jest": "^0.2.26", "@types/jest": "^29.5.1", "@types/node": "^20.2.5", diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts index 63eb58df..ad754e41 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts @@ -156,7 +156,7 @@ export class GoogleAnalytics4 extends AbstractAnalytic { * Returns page view data derived from pageData param. */ _getPageViewData(pageData: Record) { - const page_location = this._window.getUrl(); + const page_location = this._window?.getUrl(); const clientDocument = this._window?.getDocument(); const page_referrer = this.#referrer || clientDocument?.referrer; From a4649e2d33c2c54da35eb2a4e0c2350ce2fd0251 Mon Sep 17 00:00:00 2001 From: Anna Frankova Date: Thu, 11 Apr 2024 10:40:38 +0200 Subject: [PATCH 10/10] ga4-params Disable conflicting eslint rules and remove jsdoc params They would conflict with TS type generation. --- .eslintrc.js | 4 +++- packages/plugin-analytic-google/src/GoogleAnalytics4.ts | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index da63fab8..13e51993 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -24,7 +24,9 @@ module.exports = { 'jsdoc/require-returns-check': 'off', 'jsdoc/require-jsdoc': 'off', 'jsdoc/tag-lines': 'off', - + 'jsdoc/require-param': 'off', + 'jsdoc/require-returns': 'off', + 'jsdoc/require-param-type': 'off', 'no-console': [ 'error', { diff --git a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts index ad754e41..d880a737 100644 --- a/packages/plugin-analytic-google/src/GoogleAnalytics4.ts +++ b/packages/plugin-analytic-google/src/GoogleAnalytics4.ts @@ -48,8 +48,6 @@ export class GoogleAnalytics4 extends AbstractAnalytic { /** * Initializes the Google Analytics 4 plugin. - * @param config - * @param {...any} rest */ constructor( config: AnalyticGoogleSettings, @@ -68,9 +66,6 @@ export class GoogleAnalytics4 extends AbstractAnalytic { } /** * Hits custom event of given with given data - * - * @param eventName custom event name - * @param eventData custom event data */ hit(eventName: string, eventData: Record) { if (!this.isEnabled()) { @@ -82,7 +77,6 @@ export class GoogleAnalytics4 extends AbstractAnalytic { /** * Hit page view event to analytic with defined data. - * @param pageData */ hitPageView(pageData: Record) { if (!this.isEnabled()) {