From fa6bc3fc7b6341a5d21172ad073a16df14c8efe7 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdin Date: Mon, 22 Nov 2021 11:34:23 +0100 Subject: [PATCH] Merge pull request #5777 from overleaf/ab-utm-term-content Track utm_content param and replace utm_term in utm-tags property GitOrigin-RevId: 868274a3dc4f44705f1e8340592ee05acc471b19 --- .../Analytics/AnalyticsUTMTrackingMiddleware.js | 13 +++++-------- .../app/src/Features/Analytics/RequestHelper.js | 1 + .../AnalyticsUTMTrackingMiddlewareTests.js | 15 ++++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/services/web/app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware.js b/services/web/app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware.js index 1bfc14c673..f4515ff935 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware.js +++ b/services/web/app/src/Features/Analytics/AnalyticsUTMTrackingMiddleware.js @@ -22,14 +22,11 @@ function recordUTMTags() { ...utmValues, }) - const propertyValue = [ - 'utm_source', - 'utm_medium', - 'utm_campaign', - 'utm_term', - ] - .map(tag => utmValues[tag] || 'N/A') - .join(';') + const propertyValue = `${utmValues.utm_source || 'N/A'};${ + utmValues.utm_medium || 'N/A' + };${utmValues.utm_campaign || 'N/A'};${ + utmValues.utm_content || utmValues.utm_term || 'N/A' + }` AnalyticsManager.setUserPropertyForSession( req.session, 'utm-tags', diff --git a/services/web/app/src/Features/Analytics/RequestHelper.js b/services/web/app/src/Features/Analytics/RequestHelper.js index cf07bf55a7..08a6566f4c 100644 --- a/services/web/app/src/Features/Analytics/RequestHelper.js +++ b/services/web/app/src/Features/Analytics/RequestHelper.js @@ -5,6 +5,7 @@ const UTM_KEYS = [ 'utm_campaign', 'utm_source', 'utm_term', + 'utm_content', 'utm_medium', 'utm_count', ] diff --git a/services/web/test/unit/src/Analytics/AnalyticsUTMTrackingMiddlewareTests.js b/services/web/test/unit/src/Analytics/AnalyticsUTMTrackingMiddlewareTests.js index ad49450ffc..9c76b4e4ad 100644 --- a/services/web/test/unit/src/Analytics/AnalyticsUTMTrackingMiddlewareTests.js +++ b/services/web/test/unit/src/Analytics/AnalyticsUTMTrackingMiddlewareTests.js @@ -63,12 +63,13 @@ describe('AnalyticsUTMTrackingMiddleware', function () { describe('with all UTM tags in query', function () { beforeEach(function () { this.req.url = - '/project?utm_source=Organic&utm_medium=Facebook&utm_campaign=Some%20Campaign&utm_term=foo-bar' + '/project?utm_source=Organic&utm_medium=Facebook&utm_campaign=Some%20Campaign&utm_content=foo-bar&utm_term=overridden' this.req.query = { utm_source: 'Organic', utm_medium: 'Facebook', utm_campaign: 'Some Campaign', - utm_term: 'foo-bar', + utm_content: 'foo-bar', + utm_term: 'overridden', } this.middleware(this.req, this.res, this.next) }) @@ -92,7 +93,8 @@ describe('AnalyticsUTMTrackingMiddleware', function () { utm_source: 'Organic', utm_medium: 'Facebook', utm_campaign: 'Some Campaign', - utm_term: 'foo-bar', + utm_content: 'foo-bar', + utm_term: 'overridden', } ) }) @@ -109,10 +111,12 @@ describe('AnalyticsUTMTrackingMiddleware', function () { describe('with some UTM tags in query', function () { beforeEach(function () { - this.req.url = '/project?utm_medium=Facebook&utm_campaign=Some%20Campaign' + this.req.url = + '/project?utm_medium=Facebook&utm_campaign=Some%20Campaign&utm_term=foo' this.req.query = { utm_medium: 'Facebook', utm_campaign: 'Some Campaign', + utm_term: 'foo', } this.middleware(this.req, this.res, this.next) }) @@ -135,6 +139,7 @@ describe('AnalyticsUTMTrackingMiddleware', function () { path: '/project', utm_medium: 'Facebook', utm_campaign: 'Some Campaign', + utm_term: 'foo', } ) }) @@ -144,7 +149,7 @@ describe('AnalyticsUTMTrackingMiddleware', function () { this.AnalyticsManager.setUserPropertyForSession, this.req.session, 'utm-tags', - 'N/A;Facebook;Some Campaign;N/A' + 'N/A;Facebook;Some Campaign;foo' ) }) })