Merge pull request #21303 from overleaf/revert-21300-revert-20641-ar-organisation-mapping-analytics-pipeline

Revert "Revert "[web] [v1] Send salesforce modification events to analytics queues""

GitOrigin-RevId: cfcd7a6e25ad0902c699e1a34e8654347ebf71fb
This commit is contained in:
Andrew Rumble
2024-11-04 09:04:26 +00:00
committed by Copybot
parent 6f80ec0820
commit 0eaf02b4fa
7 changed files with 402 additions and 0 deletions
@@ -15,6 +15,9 @@ const analyticsEditingSessionsQueue = Queues.getQueue(
const analyticsUserPropertiesQueue = Queues.getQueue(
'analytics-user-properties'
)
const analyticsAccountMappingQueue = Queues.getQueue(
'analytics-account-mapping'
)
const ONE_MINUTE_MS = 60 * 1000
@@ -143,6 +146,55 @@ function setUserPropertyForSessionInBackground(session, property, value) {
})
}
/**
* Register mapping between two accounts.
*
* @param {object} payload - The event payload to send to Analytics
* @param {string} payload.source - The type of account linked from
* @param {string} payload.sourceId - The ID of the account linked from
* @param {string} payload.target - The type of account linked to
* @param {string} payload.targetId - The ID of the account linked to
* @param {Date} payload.createdAt - The date the mapping was created
* @property
*/
function registerAccountMapping({
source,
sourceEntity,
sourceEntityId,
target,
targetEntity,
targetEntityId,
createdAt,
}) {
Metrics.analyticsQueue.inc({
status: 'adding',
event_type: 'account-mapping',
})
analyticsAccountMappingQueue
.add('account-mapping', {
source,
sourceEntity,
sourceEntityId,
target,
targetEntity,
targetEntityId,
createdAt: createdAt ?? new Date(),
})
.then(() => {
Metrics.analyticsQueue.inc({
status: 'added',
event_type: 'account-mapping',
})
})
.catch(() => {
Metrics.analyticsQueue.inc({
status: 'error',
event_type: 'account-mapping',
})
})
}
function updateEditingSession(userId, projectId, countryCode, segmentation) {
if (!userId) {
return
@@ -349,5 +401,6 @@ module.exports = {
setUserPropertyForAnalyticsId,
updateEditingSession,
getIdsFromSession,
registerAccountMapping,
analyticsIdMiddleware: expressify(analyticsIdMiddleware),
}