Skip to content

Commit

Permalink
Introduce 'getAnonymousUserId' & 'indentifyAnonymousUser'
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 11, 2019
1 parent f975750 commit 9243543
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
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)
},
getAnonymousUserId: function() {
return {ga: null}
},
identifyAnonymousUser: function() {
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)
},
getAnonymousUserId: function() {
return {gs: null}
},
identifyAnonymousUser: function() {
return null
}
}
}
6 changes: 6 additions & 0 deletions src/adaptors/mixpanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ module.exports = function (options) {
},
track: function (prefix, type, data) {
return mixpanel.track("[" + prefix + "] " + type, data)
},
getAnonymousUserId: function() {
return {mixpanel: mixpanel.getAnonymousUserId()}
},
identifyAnonymousUser: function(id) {
return mixpanel.identifyAnonymousUser(id)
}
}
}
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
getAnonymousUserId: function(callback) {
return runForAllAdaptors('getAnonymousUserId', [], callback)
},
identifyAnonymousUserId: function(callback) {
return runForAllAdaptors('identifyAnonymousUserId', [], callback)
}
}

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

describe('All platforms', function () {
it.only('Trigger getAnonymousUserId 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.getAnonymousUserId()
.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.getAnonymousUserId()
.catch(function(err) {
expect(err.message).to.equal('(Resin Mixpanel Client) function getAnonymousUserId is only available for the browser')
done()
})
}
})
})
})

0 comments on commit 9243543

Please sign in to comment.