From 71bc4c45bcb58dfdb318e36c6262b0e2af49e0d0 Mon Sep 17 00:00:00 2001 From: MoxAmber Date: Mon, 7 Apr 2025 11:57:36 +0100 Subject: [PATCH] Merge pull request #24373 from overleaf/as-customerio-web-sdk [web] Set up customerio frontend SDK GitOrigin-RevId: 0e043163e1f6cd02d8ecf3a3e854e7799d776edd --- .../app/src/infrastructure/ExpressLocals.js | 2 ++ services/web/app/views/_customer_io.pug | 26 +++++++++++++++++++ services/web/app/views/layout-base.pug | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 services/web/app/views/_customer_io.pug diff --git a/services/web/app/src/infrastructure/ExpressLocals.js b/services/web/app/src/infrastructure/ExpressLocals.js index 002c342eef..eae1b48219 100644 --- a/services/web/app/src/infrastructure/ExpressLocals.js +++ b/services/web/app/src/infrastructure/ExpressLocals.js @@ -429,6 +429,8 @@ module.exports = function (webRouter, privateApiRouter, publicApiRouter) { wikiEnabled: Settings.overleaf != null || Settings.proxyLearn, templatesEnabled: Settings.overleaf != null || Settings.templates?.user_id != null, + cioWriteKey: Settings.analytics?.cio?.writeKey, + cioSiteId: Settings.analytics?.cio?.siteId, } next() }) diff --git a/services/web/app/views/_customer_io.pug b/services/web/app/views/_customer_io.pug new file mode 100644 index 0000000000..81d75f7d7f --- /dev/null +++ b/services/web/app/views/_customer_io.pug @@ -0,0 +1,26 @@ +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(), data-user-id=getLoggedInUserId()). + var cioSettings = document.querySelector('#cio-loader').dataset; + var analyticsId = cioSettings.sessionAnalyticsId; + var siteId = cioSettings.cioSiteId; + var writeKey = cioSettings.cioWriteKey; + var userId = cioSettings.userId; + + !function(){var i="cioanalytics", analytics=(window[i]=window[i]||[]);if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e