Merge pull request #32376 from overleaf/rh-cio-migrate-identifiers

Replace analytics id with user id as main identifier in customer.io

GitOrigin-RevId: 780671a51b652c73a940bc152d8fd6916dd611ce
This commit is contained in:
roo hutton
2026-04-02 08:05:48 +00:00
committed by Copybot
parent 972c6e4710
commit 9197be0ec7
4 changed files with 35 additions and 40 deletions
@@ -6,7 +6,6 @@ import Settings from '@overleaf/settings'
import AuthenticationController from '../Authentication/AuthenticationController.mjs'
import SessionManager from '../Authentication/SessionManager.mjs'
import SubscriptionLocator from '../Subscription/SubscriptionLocator.mjs'
import UserAnalyticsIdCache from '../Analytics/UserAnalyticsIdCache.mjs'
import _ from 'lodash'
import { expressify } from '@overleaf/promise-utils'
import Features from '../../infrastructure/Features.mjs'
@@ -217,14 +216,15 @@ async function emailPreferencesPage(req, res) {
let subscribed = false
const analyticsId = await UserAnalyticsIdCache.get(userId)
if (analyticsId) {
try {
const [preferences] = await Modules.promises.hooks.fire(
'getSubscriptionPreferences',
analyticsId
userId
)
subscribed = Boolean(preferences?.newsletter)
} catch (err) {
logger.error({ err, userId }, 'Error fetching newsletter subscription')
}
res.render('user/email-preferences', {
+5 -2
View File
@@ -1,7 +1,8 @@
if(customerIoEnabled && ExposedSettings.cioWriteKey && ExposedSettings.cioSiteId)
script(type="text/javascript", id="cio-loader", nonce=scriptNonce, data-cio-write-key=ExposedSettings.cioWriteKey, data-cio-site-id=ExposedSettings.cioSiteId, data-session-analytics-id=getSessionAnalyticsId()).
script(type="text/javascript", id="cio-loader", nonce=scriptNonce, data-cio-write-key=ExposedSettings.cioWriteKey, data-cio-site-id=ExposedSettings.cioSiteId, data-session-analytics-id=getSessionAnalyticsId(), data-user-id=((user && user._id) || '')).
var cioSettings = document.querySelector('#cio-loader').dataset;
var analyticsId = cioSettings.sessionAnalyticsId;
var userId = cioSettings.userId;
var siteId = cioSettings.cioSiteId;
var writeKey = cioSettings.cioWriteKey;
@@ -19,6 +20,8 @@ if(customerIoEnabled && ExposedSettings.cioWriteKey && ExposedSettings.cioSiteId
);
if (analyticsId) {
analytics.setAnonymousId(analyticsId);
analytics.identify(analyticsId);
}
if (userId) {
analytics.identify(userId);
};
}}();