Skip to content

Commit

Permalink
Add Sendinblue
Browse files Browse the repository at this point in the history
  • Loading branch information
sasinduh authored and wkcVishmal committed Oct 28, 2020
1 parent b6bd2ed commit d3dfb42
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@creately/siddi",
"version": "1.0.8",
"version": "1.0.9",
"description": "A convenient event tracker API which sends events to multiple consumers",
"main": "dist/siddi.js",
"scripts": {
Expand Down
45 changes: 41 additions & 4 deletions src/__tests__/consumers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ describe('Consumers', () => {

const ga = () => {};

const sendinblue = {
test: () => {},
track: () => {},
identify: () => {},
};
describe('mixpanel', () => {
beforeEach(() => {
window.mixpanel = mixpanel;
Expand Down Expand Up @@ -186,12 +191,12 @@ describe('Consumers', () => {
jest.spyOn(window, 'snowplow');
});
it('should call setUserId event', () => {
Consumers.snowplow.identify( 'vetorRajaId');
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
Consumers.snowplow.identify('vetorRajaId');
expect(window.snowplow).toHaveBeenCalledWith('setUserId', 'vetorRajaId');
});
it('should call setUserId event with additional parameter', () => {
Consumers.snowplow.identify( 'vetorRajaId', { loc: 'dd' } );
expect( window.snowplow ).toHaveBeenCalledWith( 'setUserId', 'vetorRajaId' );
Consumers.snowplow.identify('vetorRajaId', { loc: 'dd' });
expect(window.snowplow).toHaveBeenCalledWith('setUserId', 'vetorRajaId');
});
});
describe('track', () => {
Expand Down Expand Up @@ -303,5 +308,37 @@ describe('Consumers', () => {
});
});
});
describe('sendinblue', () => {
beforeEach(() => {
window.sendinblue = sendinblue;
});
describe('test', () => {
it('should return true if loaded', () => {
expect(Consumers.sendinblue.test()).toBeTruthy();
});
it('should return false if not loaded', () => {
delete window.sendinblue;
expect(Consumers.sendinblue.test()).toBeFalsy();
});
});
describe('identify', () => {
beforeEach(() => {
jest.spyOn(sendinblue, 'identify');
});
it('should register the given user', () => {
Consumers.sendinblue.identify('mock-user-id', { userProperty: 'user property' });
expect(sendinblue.identify).toBeCalledWith('mock-user-id', { userProperty: 'user property' });
});
});
describe('track', () => {
beforeEach(() => {
jest.spyOn(sendinblue, 'track');
});
it('should send given tracking data', () => {
Consumers.sendinblue.track('event.name', { prop: 'a prop' });
expect(sendinblue.track).toBeCalledWith('event.name', { prop: 'a prop' });
});
});
});
});
});
14 changes: 12 additions & 2 deletions src/consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare global {
ga: any;
snowplow: any;
snowplowschema: string; //Variable which holds the schema path
sendinblue: any;
}
}

Expand Down Expand Up @@ -94,8 +95,8 @@ export const Consumers: ConsumerConfiguration = {
snowplow: {
// TODO: Improvements to use multiple schemas
test: () => !!window.snowplow && !!window.snowplowschema,
identify: ( userId: string, _: any = {} ) => {
window.snowplow( 'setUserId', userId );
identify: (userId: string, _: any = {}) => {
window.snowplow('setUserId', userId);
},
track: (eventName: string, eventProperties: any = {}) => {
eventProperties.event = eventName;
Expand All @@ -106,4 +107,13 @@ export const Consumers: ConsumerConfiguration = {
window.snowplow('trackSelfDescribingEvent', selfDescribingEvent);
},
},
sendinblue: {
test: () => window.sendinblue,
identify: (userId: string, userProperties: any) => {
window.sendinblue.identify(userId, userProperties);
},
track: (eventName: string, eventProperties: any) => {
window.sendinblue.track(eventName, eventProperties);
},
},
};

0 comments on commit d3dfb42

Please sign in to comment.