diff --git a/src/adaptors/ga.js b/src/adaptors/ga.js index 4001974..b5651ae 100644 --- a/src/adaptors/ga.js +++ b/src/adaptors/ga.js @@ -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 } } } diff --git a/src/adaptors/gosquared.js b/src/adaptors/gosquared.js index f258338..4c760af 100644 --- a/src/adaptors/gosquared.js +++ b/src/adaptors/gosquared.js @@ -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 } } } diff --git a/src/adaptors/mixpanel.js b/src/adaptors/mixpanel.js index fc965cb..19e24ea 100644 --- a/src/adaptors/mixpanel.js +++ b/src/adaptors/mixpanel.js @@ -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) } } } diff --git a/src/resin-event-log.js b/src/resin-event-log.js index 3d9aae6..41d8bbd 100644 --- a/src/resin-event-log.js +++ b/src/resin-event-log.js @@ -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) } } diff --git a/test/resin-event-log.spec.js b/test/resin-event-log.spec.js index e8bebcc..87f4be6 100644 --- a/test/resin-event-log.spec.js +++ b/test/resin-event-log.spec.js @@ -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() + }) + } + }) + }) })