Merge pull request #4639 from overleaf/ab-web-mono-analytics-id

Analytics ID support

GitOrigin-RevId: 820a6c0f4d19f046f6c791ce4dc64dbc80748924
This commit is contained in:
Alexandre Bourdin
2021-09-09 16:45:41 +02:00
committed by Copybot
parent 3af8fc63de
commit 44a8883b6d
36 changed files with 557 additions and 249 deletions
@@ -10,6 +10,7 @@ const MODULE_PATH = path.join(
describe('AnalyticsManager', function () {
beforeEach(function () {
this.fakeUserId = '123abc'
this.analyticsId = '123456'
this.Settings = {
analytics: { enabled: true },
}
@@ -50,6 +51,9 @@ describe('AnalyticsManager', function () {
requires: {
'@overleaf/settings': this.Settings,
'../../infrastructure/Queues': this.Queues,
'./UserAnalyticsIdCache': (this.UserAnalyticsIdCache = {
get: sinon.stub().resolves(this.analyticsId),
}),
},
})
})
@@ -70,21 +74,26 @@ describe('AnalyticsManager', function () {
describe('queues the appropriate message for', function () {
it('identifyUser', function () {
const oldUserId = '456def'
this.AnalyticsManager.identifyUser(this.fakeUserId, oldUserId)
const analyticsId = '456def'
this.AnalyticsManager.identifyUser(this.fakeUserId, analyticsId)
sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'identify', {
userId: this.fakeUserId,
oldUserId,
analyticsId,
})
})
it('recordEvent', function () {
it('recordEventForUser', async function () {
const event = 'fake-event'
this.AnalyticsManager.recordEvent(this.fakeUserId, event, null)
sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'event', {
await this.AnalyticsManager.recordEventForUser(
this.fakeUserId,
event,
null
)
sinon.assert.calledWithMatch(this.analyticsEventsQueue.add, 'event', {
analyticsId: this.analyticsId,
event,
userId: this.fakeUserId,
segmentation: null,
isLoggedIn: true,
})
})