diff --git a/integrations/google-analytics-4/HISTORY.md b/integrations/google-analytics-4/HISTORY.md new file mode 100644 index 000000000..8b0fa67d0 --- /dev/null +++ b/integrations/google-analytics-4/HISTORY.md @@ -0,0 +1,9 @@ +0.0.2 / 2021-03-24 +================== + + * Fix `set` command call. + +0.0.1 / 2021-03-24 +================== + + * Initial commit :rocket: diff --git a/integrations/google-analytics-4/lib/index.js b/integrations/google-analytics-4/lib/index.js index 5e5ea705b..b5daacfe0 100644 --- a/integrations/google-analytics-4/lib/index.js +++ b/integrations/google-analytics-4/lib/index.js @@ -153,7 +153,10 @@ GA4.prototype.initialize = function() { * https://developers.google.com/gtagjs/reference/api#set */ for (var i = 0; i < sets.length; i++) { - window.gtag.apply(null, sets[i]); + // Copy the set args and append the command before calling gtag.js. + var args = sets[i].slice(0) + args.unshift('set') + window.gtag.apply(null, args); } self.ready(); diff --git a/integrations/google-analytics-4/package.json b/integrations/google-analytics-4/package.json index 9e2368316..d6a83c323 100644 --- a/integrations/google-analytics-4/package.json +++ b/integrations/google-analytics-4/package.json @@ -1,6 +1,6 @@ { "name": "@segment/analytics.js-integration-google-analytics-4", - "version": "0.0.1", + "version": "0.0.2", "description": "", "main": "lib/index.js", "directories": { diff --git a/integrations/google-analytics-4/test/index.js b/integrations/google-analytics-4/test/index.js index d873c8b0c..3dfe3de80 100644 --- a/integrations/google-analytics-4/test/index.js +++ b/integrations/google-analytics-4/test/index.js @@ -145,20 +145,19 @@ describe('Google Analytics 4', function () { analytics.equal(window.ga4DataLayer[2][2]['cookie_expires'], 21) // cookie_flags uses the `set` command - analytics.equal(window.ga4DataLayer[3][0]['cookie_flags'], 'SameSite=None;Secure') - + analytics.deepEqual(toArray(window.ga4DataLayer[3]), ['set', { cookie_flags: 'SameSite=None;Secure' }]) }); it('should disable all advertising features', function () { ga4.options.allowAllAdvertisingFeatures = false; analytics.initialize(); - analytics.deepEqual(toArray(window.ga4DataLayer[4]), ['allow_google_signals', false]) + analytics.deepEqual(toArray(window.ga4DataLayer[4]), ['set', 'allow_google_signals', false]) }); it('should disable all advertising features', function () { ga4.options.allowAdvertisingPersonalization = false; analytics.initialize(); - analytics.deepEqual(toArray(window.ga4DataLayer[5]), ['allow_ad_personalization_signals', false]) + analytics.deepEqual(toArray(window.ga4DataLayer[5]), ['set', 'allow_ad_personalization_signals', false]) }); });