Skip to content

Commit b6bd2ed

Browse files
authored
Merge pull request #15 from creately/userId-tracking-snowplow
Adding user identification for snow plow
2 parents b78628e + 1075635 commit b6bd2ed

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@creately/siddi",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A convenient event tracker API which sends events to multiple consumers",
55
"main": "dist/siddi.js",
66
"scripts": {

src/__tests__/consumers.spec.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,16 @@ describe('Consumers', () => {
182182
});
183183
});
184184
describe('identify', () => {
185-
it('should do nothing', () => {
186-
expect(Consumers.snowplow.identify()).toBeUndefined();
185+
beforeEach(() => {
186+
jest.spyOn(window, 'snowplow');
187+
});
188+
it('should call setUserId event', () => {
189+
Consumers.snowplow.identify( 'vetorRajaId');
190+
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
191+
});
192+
it('should call setUserId event with additional parameter', () => {
193+
Consumers.snowplow.identify( 'vetorRajaId', { loc: 'dd' } );
194+
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
187195
});
188196
});
189197
describe('track', () => {
@@ -200,6 +208,15 @@ describe('Consumers', () => {
200208
},
201209
});
202210
});
211+
it('should send given tracking data without additional parameter', () => {
212+
Consumers.snowplow.track('event.name');
213+
expect(window.snowplow).toBeCalledWith('trackSelfDescribingEvent', {
214+
schema: 'iglu://schema.create.ly',
215+
data: {
216+
event: 'event.name',
217+
},
218+
});
219+
});
203220
});
204221
});
205222
describe('zendesk-connect', () => {

src/consumers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export const Consumers: ConsumerConfiguration = {
9494
snowplow: {
9595
// TODO: Improvements to use multiple schemas
9696
test: () => !!window.snowplow && !!window.snowplowschema,
97-
identify: () => {
98-
// Currently no user identification is available
97+
identify: ( userId: string, _: any = {} ) => {
98+
window.snowplow( 'setUserId', userId );
9999
},
100100
track: (eventName: string, eventProperties: any = {}) => {
101101
eventProperties.event = eventName;

0 commit comments

Comments
 (0)