mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-10 22:50:46 +02:00
fcfd22a889
Revert "Revert "[web] [v1] Send salesforce modification events to analytics queues"" GitOrigin-RevId: cfcd7a6e25ad0902c699e1a34e8654347ebf71fb
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import metrics from '@overleaf/metrics'
|
|
import AnalyticsManager from './AnalyticsManager.js'
|
|
import SessionManager from '../Authentication/SessionManager.js'
|
|
import GeoIpLookup from '../../infrastructure/GeoIpLookup.js'
|
|
import Features from '../../infrastructure/Features.js'
|
|
import { expressify } from '@overleaf/promise-utils'
|
|
import { generateV1Mapping } from './AccountMappingHelper.mjs'
|
|
|
|
async function registerSalesforceMapping(req, res, next) {
|
|
if (!Features.hasFeature('analytics')) {
|
|
return res.sendStatus(202)
|
|
}
|
|
const { createdAt, salesforceId, v1Id } = req.body
|
|
AnalyticsManager.registerAccountMapping(
|
|
generateV1Mapping(v1Id, salesforceId, createdAt)
|
|
)
|
|
res.sendStatus(202)
|
|
}
|
|
|
|
async function updateEditingSession(req, res, next) {
|
|
if (!Features.hasFeature('analytics')) {
|
|
return res.sendStatus(202)
|
|
}
|
|
const userId = SessionManager.getLoggedInUserId(req.session)
|
|
const { projectId } = req.params
|
|
const segmentation = req.body.segmentation || {}
|
|
let countryCode = null
|
|
|
|
if (userId) {
|
|
try {
|
|
const geoDetails = await GeoIpLookup.promises.getDetails(req.ip)
|
|
if (geoDetails && geoDetails.country_code) {
|
|
countryCode = geoDetails.country_code
|
|
}
|
|
AnalyticsManager.updateEditingSession(
|
|
userId,
|
|
projectId,
|
|
countryCode,
|
|
segmentation
|
|
)
|
|
} catch (error) {
|
|
metrics.inc('analytics_geo_ip_lookup_errors')
|
|
}
|
|
}
|
|
res.sendStatus(202)
|
|
}
|
|
|
|
function recordEvent(req, res, next) {
|
|
if (!Features.hasFeature('analytics')) {
|
|
return res.sendStatus(202)
|
|
}
|
|
delete req.body._csrf
|
|
AnalyticsManager.recordEventForSession(
|
|
req.session,
|
|
req.params.event,
|
|
req.body
|
|
)
|
|
res.sendStatus(202)
|
|
}
|
|
|
|
export default {
|
|
registerSalesforceMapping: expressify(registerSalesforceMapping),
|
|
updateEditingSession: expressify(updateEditingSession),
|
|
recordEvent,
|
|
}
|