Skip to content

Commit 6fe76f9

Browse files
author
dinukacgx
authored
Merge pull request #16 from creately/support-sendinblue
Add Sendinblue
2 parents b6bd2ed + d3dfb42 commit 6fe76f9

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.8",
3+
"version": "1.0.9",
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: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ describe('Consumers', () => {
3636

3737
const ga = () => {};
3838

39+
const sendinblue = {
40+
test: () => {},
41+
track: () => {},
42+
identify: () => {},
43+
};
3944
describe('mixpanel', () => {
4045
beforeEach(() => {
4146
window.mixpanel = mixpanel;
@@ -186,12 +191,12 @@ describe('Consumers', () => {
186191
jest.spyOn(window, 'snowplow');
187192
});
188193
it('should call setUserId event', () => {
189-
Consumers.snowplow.identify( 'vetorRajaId');
190-
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
194+
Consumers.snowplow.identify('vetorRajaId');
195+
expect(window.snowplow).toHaveBeenCalledWith('setUserId', 'vetorRajaId');
191196
});
192197
it('should call setUserId event with additional parameter', () => {
193-
Consumers.snowplow.identify( 'vetorRajaId', { loc: 'dd' } );
194-
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
198+
Consumers.snowplow.identify('vetorRajaId', { loc: 'dd' });
199+
expect(window.snowplow).toHaveBeenCalledWith('setUserId', 'vetorRajaId');
195200
});
196201
});
197202
describe('track', () => {
@@ -303,5 +308,37 @@ describe('Consumers', () => {
303308
});
304309
});
305310
});
311+
describe('sendinblue', () => {
312+
beforeEach(() => {
313+
window.sendinblue = sendinblue;
314+
});
315+
describe('test', () => {
316+
it('should return true if loaded', () => {
317+
expect(Consumers.sendinblue.test()).toBeTruthy();
318+
});
319+
it('should return false if not loaded', () => {
320+
delete window.sendinblue;
321+
expect(Consumers.sendinblue.test()).toBeFalsy();
322+
});
323+
});
324+
describe('identify', () => {
325+
beforeEach(() => {
326+
jest.spyOn(sendinblue, 'identify');
327+
});
328+
it('should register the given user', () => {
329+
Consumers.sendinblue.identify('mock-user-id', { userProperty: 'user property' });
330+
expect(sendinblue.identify).toBeCalledWith('mock-user-id', { userProperty: 'user property' });
331+
});
332+
});
333+
describe('track', () => {
334+
beforeEach(() => {
335+
jest.spyOn(sendinblue, 'track');
336+
});
337+
it('should send given tracking data', () => {
338+
Consumers.sendinblue.track('event.name', { prop: 'a prop' });
339+
expect(sendinblue.track).toBeCalledWith('event.name', { prop: 'a prop' });
340+
});
341+
});
342+
});
306343
});
307344
});

src/consumers.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ declare global {
2525
ga: any;
2626
snowplow: any;
2727
snowplowschema: string; //Variable which holds the schema path
28+
sendinblue: any;
2829
}
2930
}
3031

@@ -94,8 +95,8 @@ export const Consumers: ConsumerConfiguration = {
9495
snowplow: {
9596
// TODO: Improvements to use multiple schemas
9697
test: () => !!window.snowplow && !!window.snowplowschema,
97-
identify: ( userId: string, _: any = {} ) => {
98-
window.snowplow( 'setUserId', userId );
98+
identify: (userId: string, _: any = {}) => {
99+
window.snowplow('setUserId', userId);
99100
},
100101
track: (eventName: string, eventProperties: any = {}) => {
101102
eventProperties.event = eventName;
@@ -106,4 +107,13 @@ export const Consumers: ConsumerConfiguration = {
106107
window.snowplow('trackSelfDescribingEvent', selfDescribingEvent);
107108
},
108109
},
110+
sendinblue: {
111+
test: () => window.sendinblue,
112+
identify: (userId: string, userProperties: any) => {
113+
window.sendinblue.identify(userId, userProperties);
114+
},
115+
track: (eventName: string, eventProperties: any) => {
116+
window.sendinblue.track(eventName, eventProperties);
117+
},
118+
},
109119
};

0 commit comments

Comments
 (0)