Skip to content

Commit

Permalink
Introduce 'getDistinctId' & 'identify'
Browse files Browse the repository at this point in the history
Connects-to: #5
Change-type: major
Signed-off-by: Dimitrios Lytras <dimitrios@balena.io>
  • Loading branch information
dimitrisnl committed Apr 19, 2019
1 parent 3317172 commit 60b8086
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 7 deletions.
12 changes: 6 additions & 6 deletions 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
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"bluebird": "^3.4.7",
"lodash": "^4.0.0",
"resin-mixpanel-client": "^2.2.1",
"resin-mixpanel-client": "^2.4.0",
"resin-universal-ga": "^1.2.2",
"resin-universal-gosquared": "^0.2.0"
},
Expand Down
6 changes: 6 additions & 0 deletions src/adaptors/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ module.exports = function (options) {
},
track: function (prefix, type, data) {
return gaClient.track(site, type, prefix, data)
},
getDistinctId: function() {
return {ga: null}
},
identify: function(ids) {
return null
}
}
}
6 changes: 6 additions & 0 deletions src/adaptors/gosquared.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ module.exports = function (options) {
},
track: function (prefix, type, data) {
return gsClient.track(prefix, type, data)
},
getDistinctId: function() {
return {gs: null}
},
identify: function(ids) {
return null
}
}
}
12 changes: 12 additions & 0 deletions src/adaptors/mixpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ module.exports = function (options) {
},
track: function (prefix, type, data) {
return mixpanel.track("[" + prefix + "] " + type, data)
},
getDistinctId: function() {
return {mixpanel: mixpanel.getDistinctId()}
},
identify: function(ids) {
var mixpanelId = ids['mixpanel']

if (!mixpanelId){
return null
}

return mixpanel.identify(mixpanelId)
}
}
}
7 changes: 7 additions & 0 deletions src/resin-event-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ module.exports = function(options) {
}).then(function () {
return runAfterHook()
}).asCallback(callback)
},
// These functions are only available for use in the browser
getDistinctId: function(callback) {
return runForAllAdaptors('getDistinctId', [], callback)
},
identify: function(ids, callback) {
return runForAllAdaptors('identify', [ids], callback)
}
}

Expand Down
69 changes: 69 additions & 0 deletions tests/resin-event-log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,4 +828,73 @@ describe('ResinEventLog', function () {
})
})
})

describe('All platforms', function () {
it('Trigger getDistinctId in browser & fail in node', function (done) {
eventLog = ResinEventLog({
mixpanelToken: MIXPANEL_TOKEN,
gaId: GA_ID,
gaSite: GA_SITE,
gosquaredId: GOSQUARED_ID,
gosquaredApiKey: GOSQUARED_API_KEY,
prefix: SYSTEM,
debug: EXTRA_DEBUG,
})

if(IS_BROWSER) {
eventLog.getDistinctId()
.then(function(platformIds) {
expect(platformIds).to.have.lengthOf(3);
// GA
expect(platformIds[0]).to.have.property('ga');
expect(platformIds[0]['ga']).to.be.null;
// Mixpanel
expect(platformIds[1]).to.have.property('mixpanel');
expect(platformIds[1]['mixpanel']).to.be.a('string');
// GS
expect(platformIds[2]).to.have.property('gs');
expect(platformIds[2]['gs']).to.be.null;

done()
})
}
else{
eventLog.getDistinctId()
.catch(function(err) {
expect(err.message).to.equal('(Resin Mixpanel Client) function getDistinctId is only available for the browser')
done()
})
}
})

it('Trigger identify in browser & fail in node', function (done) {
eventLog = ResinEventLog({
mixpanelToken: MIXPANEL_TOKEN,
gaId: GA_ID,
gaSite: GA_SITE,
gosquaredId: GOSQUARED_ID,
gosquaredApiKey: GOSQUARED_API_KEY,
prefix: SYSTEM,
debug: EXTRA_DEBUG,
})

if(IS_BROWSER) {
eventLog.identify({
mixpanel: 'dummy_id'
})
.then(function() {
done()
})
}
else{
eventLog.identify({
mixpanel: 'dummy_id'
})
.catch(function(err) {
expect(err.message).to.equal('(Resin Mixpanel Client) function identify is only available for the browser')
done()
})
}
})
})
})

0 comments on commit 60b8086

Please sign in to comment.