Skip to content
This repository was archived by the owner on Nov 27, 2019. It is now read-only.

Commit 675cd1d

Browse files
authored
Merge pull request #4 from segment-integrations/add-userId
push userId to data layer for track calls
2 parents 14212b4 + 79f6df1 commit 675cd1d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ GTM.prototype.page = function(page) {
8383

8484
GTM.prototype.track = function(track) {
8585
var props = track.properties();
86+
var id = this.analytics.user().id();
87+
if (id) props.userId = id;
8688
props.event = track.event();
89+
8790
push(props);
8891
};

test/index.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ describe('Google Tag Manager', function() {
6767
analytics.called(window.dataLayer.push, { event: 'some-event' });
6868
});
6969

70+
it('should send userId if it exists', function() {
71+
analytics.user().id('pablo');
72+
analytics.track('some-event');
73+
analytics.called(window.dataLayer.push, { userId: 'pablo', event: 'some-event' });
74+
});
75+
7076
it('should send event with properties', function() {
7177
analytics.track('event', { prop: true });
7278
analytics.called(window.dataLayer.push, { event: 'event', prop: true });

0 commit comments

Comments
 (0)