mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #3726 from overleaf/ta-ab-analytics-events
Add new analytics events GitOrigin-RevId: f71a6dc5ccd44bdabb48c601f9f0e005cc765077
This commit is contained in:
parent
623d77cef6
commit
9415a1dd8d
4 changed files with 38 additions and 2 deletions
|
@ -8,6 +8,7 @@ const logger = require('logger-sharelatex')
|
|||
const V1Api = require('../V1/V1Api')
|
||||
const crypto = require('crypto')
|
||||
const { promisifyAll } = require('../../util/promises')
|
||||
const Analytics = require('../Analytics/AnalyticsManager')
|
||||
|
||||
const READ_AND_WRITE_TOKEN_PATTERN = '([0-9]+[a-z]{6,12})'
|
||||
const READ_ONLY_TOKEN_PATTERN = '([a-z]{12})'
|
||||
|
@ -164,6 +165,7 @@ const TokenAccessHandler = {
|
|||
addReadOnlyUserToProject(userId, projectId, callback) {
|
||||
userId = ObjectId(userId.toString())
|
||||
projectId = ObjectId(projectId.toString())
|
||||
Analytics.recordEvent(userId, 'project-joined', { mode: 'read-only' })
|
||||
Project.updateOne(
|
||||
{
|
||||
_id: projectId
|
||||
|
@ -178,6 +180,7 @@ const TokenAccessHandler = {
|
|||
addReadAndWriteUserToProject(userId, projectId, callback) {
|
||||
userId = ObjectId(userId.toString())
|
||||
projectId = ObjectId(projectId.toString())
|
||||
Analytics.recordEvent(userId, 'project-joined', { mode: 'read-write' })
|
||||
Project.updateOne(
|
||||
{
|
||||
_id: projectId
|
||||
|
|
|
@ -6,6 +6,7 @@ const { User } = require('../../models/User')
|
|||
const UserDeleter = require('./UserDeleter')
|
||||
const UserGetter = require('./UserGetter')
|
||||
const UserUpdater = require('./UserUpdater')
|
||||
const Analytics = require('../Analytics/AnalyticsManager')
|
||||
|
||||
async function _addAffiliation(user, affiliationOptions) {
|
||||
try {
|
||||
|
@ -82,6 +83,8 @@ async function createNewUser(attributes, options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
Analytics.recordEvent(user._id, 'user-registered')
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,10 @@ describe('TokenAccessHandler', function() {
|
|||
'../V1/V1Api': (this.V1Api = {
|
||||
request: sinon.stub()
|
||||
}),
|
||||
crypto: (this.Crypto = require('crypto'))
|
||||
crypto: (this.Crypto = require('crypto')),
|
||||
'../Analytics/AnalyticsManager': (this.Analytics = {
|
||||
recordEvent: sinon.stub()
|
||||
})
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
@ -140,6 +143,12 @@ describe('TokenAccessHandler', function() {
|
|||
expect(
|
||||
this.Project.updateOne.lastCall.args[1].$addToSet
|
||||
).to.have.keys('tokenAccessReadOnly_refs')
|
||||
sinon.assert.calledWith(
|
||||
this.Analytics.recordEvent,
|
||||
this.userId,
|
||||
'project-joined',
|
||||
{ mode: 'read-only' }
|
||||
)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
@ -195,6 +204,12 @@ describe('TokenAccessHandler', function() {
|
|||
expect(
|
||||
this.Project.updateOne.lastCall.args[1].$addToSet
|
||||
).to.have.keys('tokenAccessReadAndWrite_refs')
|
||||
sinon.assert.calledWith(
|
||||
this.Analytics.recordEvent,
|
||||
this.userId,
|
||||
'project-joined',
|
||||
{ mode: 'read-write' }
|
||||
)
|
||||
return done()
|
||||
}
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@ const SandboxedModule = require('sandboxed-module')
|
|||
const chai = require('chai')
|
||||
const sinon = require('sinon')
|
||||
|
||||
const assert = chai.assert
|
||||
const { assert } = chai
|
||||
const modulePath = '../../../../app/src/Features/User/UserCreator.js'
|
||||
|
||||
describe('UserCreator', function() {
|
||||
|
@ -47,6 +47,9 @@ describe('UserCreator', function() {
|
|||
.resolves({ n: 1, nModified: 1, ok: 1 }),
|
||||
updateUser: sinon.stub().resolves()
|
||||
}
|
||||
}),
|
||||
'../Analytics/AnalyticsManager': (this.Analytics = {
|
||||
recordEvent: sinon.stub()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
@ -261,6 +264,18 @@ describe('UserCreator', function() {
|
|||
const user = await this.UserCreator.promises.createNewUser(attributes)
|
||||
assert.equal(user.emails[0].samlProviderId, '1')
|
||||
})
|
||||
|
||||
it('should fire an analytics event on registration', async function() {
|
||||
const user = await this.UserCreator.promises.createNewUser({
|
||||
email: this.email
|
||||
})
|
||||
assert.equal(user.email, this.email)
|
||||
sinon.assert.calledWith(
|
||||
this.Analytics.recordEvent,
|
||||
user._id,
|
||||
'user-registered'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue