Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions integrations/google-analytics-4/HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0.0.2 / 2021-03-24
==================

* Fix `set` command call.

0.0.1 / 2021-03-24
==================

* Initial commit :rocket:
5 changes: 4 additions & 1 deletion integrations/google-analytics-4/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion integrations/google-analytics-4/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions integrations/google-analytics-4/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
});
});

Expand Down