From 85f5a355829178f4444dfc4744009331349ce580 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Wed, 12 Apr 2023 07:39:06 -0700 Subject: [PATCH 01/19] Add AA launch scripts and DCR on tracked events --- packages/manager/src/App.tsx | 8 ++++++++ packages/manager/src/constants.ts | 6 ++++++ packages/manager/src/utilities/ga.ts | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 633bbc56e58..efec7d877a4 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,6 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; +import { ADOBE_ANALYTICS_DEV } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -83,6 +84,13 @@ export class App extends React.Component { loadScript('/new-relic.js'); } + // Load Adobe Analytics Launch Script + const script = document.createElement('script'); + // eslint-disable-next-line scanjs-rules/assign_to_src + script.src = `${ADOBE_ANALYTICS_DEV}`; // Use dev to test for now + script.async = true; + document.head.appendChild(script); + /** * Send pageviews unless blocklisted. */ diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index 6293d27d96f..e3526fbf743 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,6 +66,12 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; +/** Adobe Analytics Launch scripts */ +export const ADOBE_ANALYTICS_DEV = + 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-09b7ca9d43ad-development.min.js'; +export const ADOBE_ANALYTICS_STAGING = + 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-a50be9afbe1d-staging.min.js'; + /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 383030187c5..8bc85cbdbb0 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -12,6 +12,12 @@ interface AnalyticsEvent { * Will throw error unless analytics is initialized */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { + // Send a Direct Call Rule to Adobe + (window as any)._satellite.track(eventPayload.category, { + label: eventPayload.label, + action: eventPayload.action, + }); + /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; }; From ee460fc1e7ef6851207d55ff117f4c7b9c323dab Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 08:04:48 -0700 Subject: [PATCH 02/19] Update satellite.track function to use generic, single identifier --- packages/manager/src/utilities/ga.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 8bc85cbdbb0..2ee1112b448 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -13,9 +13,11 @@ interface AnalyticsEvent { */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { // Send a Direct Call Rule to Adobe - (window as any)._satellite.track(eventPayload.category, { - label: eventPayload.label, + (window as any)._satellite.track('custom event', { + category: eventPayload.category, action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, }); /** only send events if we have a GA ID */ From dda27ec041fae0b0ff3077f31a971657805520e2 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 08:06:05 -0700 Subject: [PATCH 03/19] Update launch script src assignment with logic for additional envs --- packages/manager/src/App.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index efec7d877a4..78cddc5fc0b 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,7 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; -import { ADOBE_ANALYTICS_DEV } from './constants'; +import { ADOBE_ANALYTICS_DEV, ADOBE_ANALYTICS_STAGING } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -87,7 +87,13 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ADOBE_ANALYTICS_DEV}`; // Use dev to test for now + script.src = `${ + import.meta.env.PROD + ? ADOBE_ANALYTICS_STAGING // TODO: update with prod launch script url + : import.meta.env.DEV + ? ADOBE_ANALYTICS_DEV + : undefined + }`; script.async = true; document.head.appendChild(script); From 92e8d4282ae8beb3e78caaeebc24979db47e8c9f Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 13:09:20 -0700 Subject: [PATCH 04/19] Use a single env var from Jenkins --- packages/manager/src/App.tsx | 9 +-------- packages/manager/src/constants.ts | 5 ----- packages/manager/src/env.d.ts | 1 + 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 78cddc5fc0b..dcce15faf7e 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,7 +41,6 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; -import { ADOBE_ANALYTICS_DEV, ADOBE_ANALYTICS_STAGING } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -87,13 +86,7 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ - import.meta.env.PROD - ? ADOBE_ANALYTICS_STAGING // TODO: update with prod launch script url - : import.meta.env.DEV - ? ADOBE_ANALYTICS_DEV - : undefined - }`; + script.src = `${import.meta.env.REACT_APP_ADOBE_ANALYTICS_URL}`; script.async = true; document.head.appendChild(script); diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index e3526fbf743..b9c8a1a613c 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,11 +66,6 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; -/** Adobe Analytics Launch scripts */ -export const ADOBE_ANALYTICS_DEV = - 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-09b7ca9d43ad-development.min.js'; -export const ADOBE_ANALYTICS_STAGING = - 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-a50be9afbe1d-staging.min.js'; /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; diff --git a/packages/manager/src/env.d.ts b/packages/manager/src/env.d.ts index a37e567de60..dea848501aa 100644 --- a/packages/manager/src/env.d.ts +++ b/packages/manager/src/env.d.ts @@ -14,6 +14,7 @@ interface ImportMetaEnv { REACT_APP_ACCESS_TOKEN?: string; REACT_APP_GTM_ID?: string; REACT_APP_GA_ID?: string; + REACT_APP_ADOBE_ANALYTICS_URL?: string; REACT_APP_SENTRY_URL?: string; REACT_APP_GPAY_ENV?: 'TEST' | 'PRODUCTION'; REACT_APP_GPAY_MERCHANT_ID?: string; From c58203499aa5e9dfb3a4c8d5959671efae4a7b8e Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 13:11:13 -0700 Subject: [PATCH 05/19] Disable tracking on custom events in Adobe for now --- packages/manager/src/utilities/ga.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 2ee1112b448..89c8fd2c2c1 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -13,12 +13,13 @@ interface AnalyticsEvent { */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { // Send a Direct Call Rule to Adobe - (window as any)._satellite.track('custom event', { - category: eventPayload.category, - action: eventPayload.action, - label: eventPayload.label, - value: eventPayload.value, - }); + // TODO: uncomment in forthcoming PR once basic tracking is verified + // (window as any)._satellite.track('custom event', { + // category: eventPayload.category, + // action: eventPayload.action, + // label: eventPayload.label, + // value: eventPayload.value, + // }); /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; From 3130710d5bedcca63d98d4adc3ee291d0943a006 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Fri, 14 Apr 2023 08:59:08 -0700 Subject: [PATCH 06/19] Cleanup --- packages/manager/src/App.tsx | 3 ++- packages/manager/src/constants.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index dcce15faf7e..3b6dc42b702 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,6 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; +import { ADOBE_ANALYTICS_URL } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -86,7 +87,7 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${import.meta.env.REACT_APP_ADOBE_ANALYTICS_URL}`; + script.src = `${ADOBE_ANALYTICS_URL}`; script.async = true; document.head.appendChild(script); diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index b9c8a1a613c..3ef3b1beedb 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,7 +66,9 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; - +/** Adobe Analytics */ +export const ADOBE_ANALYTICS_URL = import.meta.env + .REACT_APP_ADOBE_ANALYTICS_URL; /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; From 9f7b914070660bf4cf749d90800fdaf6638c796a Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Fri, 14 Apr 2023 13:46:17 -0700 Subject: [PATCH 07/19] Enable direct call rule for AA custom event tracking --- packages/manager/src/utilities/ga.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 89c8fd2c2c1..2ee1112b448 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -13,13 +13,12 @@ interface AnalyticsEvent { */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { // Send a Direct Call Rule to Adobe - // TODO: uncomment in forthcoming PR once basic tracking is verified - // (window as any)._satellite.track('custom event', { - // category: eventPayload.category, - // action: eventPayload.action, - // label: eventPayload.label, - // value: eventPayload.value, - // }); + (window as any)._satellite.track('custom event', { + category: eventPayload.category, + action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, + }); /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; From 8a7c482d36339a2fcec1157937168485e16bea62 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Wed, 12 Apr 2023 07:39:06 -0700 Subject: [PATCH 08/19] Add AA launch scripts and DCR on tracked events --- packages/manager/src/App.tsx | 8 ++++++++ packages/manager/src/constants.ts | 6 ++++++ packages/manager/src/utilities/ga.ts | 6 ++++++ 3 files changed, 20 insertions(+) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 633bbc56e58..efec7d877a4 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,6 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; +import { ADOBE_ANALYTICS_DEV } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -83,6 +84,13 @@ export class App extends React.Component { loadScript('/new-relic.js'); } + // Load Adobe Analytics Launch Script + const script = document.createElement('script'); + // eslint-disable-next-line scanjs-rules/assign_to_src + script.src = `${ADOBE_ANALYTICS_DEV}`; // Use dev to test for now + script.async = true; + document.head.appendChild(script); + /** * Send pageviews unless blocklisted. */ diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index 6293d27d96f..e3526fbf743 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,6 +66,12 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; +/** Adobe Analytics Launch scripts */ +export const ADOBE_ANALYTICS_DEV = + 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-09b7ca9d43ad-development.min.js'; +export const ADOBE_ANALYTICS_STAGING = + 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-a50be9afbe1d-staging.min.js'; + /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 383030187c5..8bc85cbdbb0 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -12,6 +12,12 @@ interface AnalyticsEvent { * Will throw error unless analytics is initialized */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { + // Send a Direct Call Rule to Adobe + (window as any)._satellite.track(eventPayload.category, { + label: eventPayload.label, + action: eventPayload.action, + }); + /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; }; From 5a4adb787be90ebec8951f6bfb3cecd01f402890 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 08:04:48 -0700 Subject: [PATCH 09/19] Update satellite.track function to use generic, single identifier --- packages/manager/src/utilities/ga.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 8bc85cbdbb0..2ee1112b448 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -13,9 +13,11 @@ interface AnalyticsEvent { */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { // Send a Direct Call Rule to Adobe - (window as any)._satellite.track(eventPayload.category, { - label: eventPayload.label, + (window as any)._satellite.track('custom event', { + category: eventPayload.category, action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, }); /** only send events if we have a GA ID */ From e8558607095ba24ce7d9793515552f55cf94acdf Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 08:06:05 -0700 Subject: [PATCH 10/19] Update launch script src assignment with logic for additional envs --- packages/manager/src/App.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index efec7d877a4..78cddc5fc0b 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,7 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; -import { ADOBE_ANALYTICS_DEV } from './constants'; +import { ADOBE_ANALYTICS_DEV, ADOBE_ANALYTICS_STAGING } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -87,7 +87,13 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ADOBE_ANALYTICS_DEV}`; // Use dev to test for now + script.src = `${ + import.meta.env.PROD + ? ADOBE_ANALYTICS_STAGING // TODO: update with prod launch script url + : import.meta.env.DEV + ? ADOBE_ANALYTICS_DEV + : undefined + }`; script.async = true; document.head.appendChild(script); From dfaf6afb694a42a4ecdcd11b1e4aa68b63edd20b Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 13:09:20 -0700 Subject: [PATCH 11/19] Use a single env var from Jenkins --- packages/manager/src/App.tsx | 9 +-------- packages/manager/src/constants.ts | 5 ----- packages/manager/src/env.d.ts | 1 + 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 78cddc5fc0b..dcce15faf7e 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,7 +41,6 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; -import { ADOBE_ANALYTICS_DEV, ADOBE_ANALYTICS_STAGING } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -87,13 +86,7 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ - import.meta.env.PROD - ? ADOBE_ANALYTICS_STAGING // TODO: update with prod launch script url - : import.meta.env.DEV - ? ADOBE_ANALYTICS_DEV - : undefined - }`; + script.src = `${import.meta.env.REACT_APP_ADOBE_ANALYTICS_URL}`; script.async = true; document.head.appendChild(script); diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index e3526fbf743..b9c8a1a613c 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,11 +66,6 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; -/** Adobe Analytics Launch scripts */ -export const ADOBE_ANALYTICS_DEV = - 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-09b7ca9d43ad-development.min.js'; -export const ADOBE_ANALYTICS_STAGING = - 'https://assets.adobedtm.com/fcfd3580c848/795fdfec4a0e/launch-a50be9afbe1d-staging.min.js'; /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; diff --git a/packages/manager/src/env.d.ts b/packages/manager/src/env.d.ts index a37e567de60..dea848501aa 100644 --- a/packages/manager/src/env.d.ts +++ b/packages/manager/src/env.d.ts @@ -14,6 +14,7 @@ interface ImportMetaEnv { REACT_APP_ACCESS_TOKEN?: string; REACT_APP_GTM_ID?: string; REACT_APP_GA_ID?: string; + REACT_APP_ADOBE_ANALYTICS_URL?: string; REACT_APP_SENTRY_URL?: string; REACT_APP_GPAY_ENV?: 'TEST' | 'PRODUCTION'; REACT_APP_GPAY_MERCHANT_ID?: string; From df22a2ca28e58302f6b2b238cf110edf950a9efb Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 13 Apr 2023 13:11:13 -0700 Subject: [PATCH 12/19] Disable tracking on custom events in Adobe for now --- packages/manager/src/utilities/ga.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 2ee1112b448..89c8fd2c2c1 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -13,12 +13,13 @@ interface AnalyticsEvent { */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { // Send a Direct Call Rule to Adobe - (window as any)._satellite.track('custom event', { - category: eventPayload.category, - action: eventPayload.action, - label: eventPayload.label, - value: eventPayload.value, - }); + // TODO: uncomment in forthcoming PR once basic tracking is verified + // (window as any)._satellite.track('custom event', { + // category: eventPayload.category, + // action: eventPayload.action, + // label: eventPayload.label, + // value: eventPayload.value, + // }); /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; From 5ad562594e4d1cb18a4009401ad46076b31e896a Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Fri, 14 Apr 2023 08:59:08 -0700 Subject: [PATCH 13/19] Cleanup --- packages/manager/src/App.tsx | 3 ++- packages/manager/src/constants.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index dcce15faf7e..3b6dc42b702 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -41,6 +41,7 @@ import { sshKeyEventHandler } from './queries/profile'; import { firewallEventsHandler } from './queries/firewalls'; import { nodebalanacerEventHandler } from './queries/nodebalancers'; import { oauthClientsEventHandler } from './queries/accountOAuth'; +import { ADOBE_ANALYTICS_URL } from './constants'; interface Props { location: RouteComponentProps['location']; @@ -86,7 +87,7 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${import.meta.env.REACT_APP_ADOBE_ANALYTICS_URL}`; + script.src = `${ADOBE_ANALYTICS_URL}`; script.async = true; document.head.appendChild(script); diff --git a/packages/manager/src/constants.ts b/packages/manager/src/constants.ts index b9c8a1a613c..3ef3b1beedb 100644 --- a/packages/manager/src/constants.ts +++ b/packages/manager/src/constants.ts @@ -66,7 +66,9 @@ export const OAUTH_TOKEN_REFRESH_TIMEOUT = LOGIN_SESSION_LIFETIME_MS / 2; /** Google Analytics and Tag Manager */ export const GA_ID = import.meta.env.REACT_APP_GA_ID; export const GTM_ID = import.meta.env.REACT_APP_GTM_ID; - +/** Adobe Analytics */ +export const ADOBE_ANALYTICS_URL = import.meta.env + .REACT_APP_ADOBE_ANALYTICS_URL; /** for hard-coding token used for API Requests. Example: "Bearer 1234" */ export const ACCESS_TOKEN = import.meta.env.REACT_APP_ACCESS_TOKEN; From bdc5802591fdee0eb7acc24fb3bae5fb47ed3d7d Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Mon, 17 Apr 2023 19:30:31 -0700 Subject: [PATCH 14/19] Only append Adobe Analytics script with valid url --- packages/manager/src/App.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 3b6dc42b702..13c026a423a 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -85,11 +85,13 @@ export class App extends React.Component { } // Load Adobe Analytics Launch Script - const script = document.createElement('script'); - // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ADOBE_ANALYTICS_URL}`; - script.async = true; - document.head.appendChild(script); + if (ADOBE_ANALYTICS_URL) { + const script = document.createElement('script'); + // eslint-disable-next-line scanjs-rules/assign_to_src + script.src = `${ADOBE_ANALYTICS_URL}`; + script.async = true; + document.head.appendChild(script); + } /** * Send pageviews unless blocklisted. From 94489c0e45ca4910bb8f9525f597de083a5a2d33 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Tue, 18 Apr 2023 08:48:35 -0700 Subject: [PATCH 15/19] Prevent errors if AA env is not defined --- packages/manager/src/App.tsx | 2 +- packages/manager/src/utilities/ga.ts | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 13c026a423a..7fcaa0ea1fe 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -85,7 +85,7 @@ export class App extends React.Component { } // Load Adobe Analytics Launch Script - if (ADOBE_ANALYTICS_URL) { + if (!!ADOBE_ANALYTICS_URL) { const script = document.createElement('script'); // eslint-disable-next-line scanjs-rules/assign_to_src script.src = `${ADOBE_ANALYTICS_URL}`; diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 2ee1112b448..3554c6432b4 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -1,5 +1,5 @@ import { event } from 'react-ga'; -import { GA_ID } from 'src/constants'; +import { GA_ID, ADOBE_ANALYTICS_URL } from 'src/constants'; interface AnalyticsEvent { category: string; @@ -12,13 +12,19 @@ interface AnalyticsEvent { * Will throw error unless analytics is initialized */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { - // Send a Direct Call Rule to Adobe - (window as any)._satellite.track('custom event', { - category: eventPayload.category, - action: eventPayload.action, - label: eventPayload.label, - value: eventPayload.value, - }); + // Send a Direct Call Rule if our environment is configured with an Adobe Launch script + if (!!ADOBE_ANALYTICS_URL) { + try { + (window as any)._satellite.track('custom event', { + category: eventPayload.category, + action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, + }); + } catch { + return undefined; + } + } /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; From ab2b003282fded612a506e08ce77a97799482730 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Wed, 19 Apr 2023 14:36:54 -0700 Subject: [PATCH 16/19] Update sendEvent --- packages/manager/src/utilities/ga.ts | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 3554c6432b4..5e15e765524 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -1,5 +1,5 @@ import { event } from 'react-ga'; -import { GA_ID, ADOBE_ANALYTICS_URL } from 'src/constants'; +import { GA_ID, ADOBE_ANALYTICS_URL, isProductionBuild } from 'src/constants'; interface AnalyticsEvent { category: string; @@ -8,24 +8,26 @@ interface AnalyticsEvent { value?: number; } -/* - * Will throw error unless analytics is initialized - */ export const sendEvent = (eventPayload: AnalyticsEvent): void => { - // Send a Direct Call Rule if our environment is configured with an Adobe Launch script - if (!!ADOBE_ANALYTICS_URL) { - try { - (window as any)._satellite.track('custom event', { - category: eventPayload.category, - action: eventPayload.action, - label: eventPayload.label, - value: eventPayload.value, - }); - } catch { - return undefined; - } + if (!ADOBE_ANALYTICS_URL) { + return; + } + + // Log error to console in local environment + if (!isProductionBuild && !(window as any)._satellite) { + // eslint-disable-next-line no-console + console.error('Adobe Launch script not loaded; no analytics will be sent'); + return; } + // Send a Direct Call Rule if our environment is configured with an Adobe Launch script + (window as any)._satellite.track('custom event', { + category: eventPayload.category, + action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, + }); + /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined; }; From 787b729816ae0379124705b9fe8bbacc99df072a Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Wed, 19 Apr 2023 15:39:52 -0700 Subject: [PATCH 17/19] Test if loadScript works instead --- packages/manager/src/App.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index 7fcaa0ea1fe..a658902297d 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -86,11 +86,7 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script if (!!ADOBE_ANALYTICS_URL) { - const script = document.createElement('script'); - // eslint-disable-next-line scanjs-rules/assign_to_src - script.src = `${ADOBE_ANALYTICS_URL}`; - script.async = true; - document.head.appendChild(script); + loadScript(ADOBE_ANALYTICS_URL); } /** From f9d492a02b4b712bb284d60d006007afea1b5899 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Thu, 20 Apr 2023 10:43:05 -0700 Subject: [PATCH 18/19] Revert previous commit to move location of script --- packages/manager/src/App.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/manager/src/App.tsx b/packages/manager/src/App.tsx index a658902297d..7fcaa0ea1fe 100644 --- a/packages/manager/src/App.tsx +++ b/packages/manager/src/App.tsx @@ -86,7 +86,11 @@ export class App extends React.Component { // Load Adobe Analytics Launch Script if (!!ADOBE_ANALYTICS_URL) { - loadScript(ADOBE_ANALYTICS_URL); + const script = document.createElement('script'); + // eslint-disable-next-line scanjs-rules/assign_to_src + script.src = `${ADOBE_ANALYTICS_URL}`; + script.async = true; + document.head.appendChild(script); } /** From e39a7f119e8eaf5f90d3d52c9e23db6d02b63fa9 Mon Sep 17 00:00:00 2001 From: mjac0bs Date: Fri, 21 Apr 2023 10:14:28 -0700 Subject: [PATCH 19/19] Log error when sendEvent fails --- packages/manager/src/utilities/ga.ts | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/manager/src/utilities/ga.ts b/packages/manager/src/utilities/ga.ts index 025ecc5a8bc..4b3a53d99eb 100644 --- a/packages/manager/src/utilities/ga.ts +++ b/packages/manager/src/utilities/ga.ts @@ -1,5 +1,6 @@ import { event } from 'react-ga'; -import { GA_ID, ADOBE_ANALYTICS_URL, isProductionBuild } from 'src/constants'; +import { GA_ID, ADOBE_ANALYTICS_URL } from 'src/constants'; +import { reportException } from 'src/exceptionReporting'; interface AnalyticsEvent { category: string; @@ -13,20 +14,20 @@ export const sendEvent = (eventPayload: AnalyticsEvent): void => { return; } - // Log error to console in local environment - if (!isProductionBuild && !(window as any)._satellite) { - // eslint-disable-next-line no-console - console.error('Adobe Launch script not loaded; no analytics will be sent'); - return; - } - // Send a Direct Call Rule if our environment is configured with an Adobe Launch script - (window as any)._satellite.track('custom event', { - category: eventPayload.category, - action: eventPayload.action, - label: eventPayload.label, - value: eventPayload.value, - }); + try { + (window as any)._satellite.track('custom event', { + category: eventPayload.category, + action: eventPayload.action, + label: eventPayload.label, + value: eventPayload.value, + }); + } catch (error) { + reportException(error, { + message: + 'An error occurred when tracking a custom event. Adobe Launch script not loaded correctly; no analytics will be sent.', + }); + } /** only send events if we have a GA ID */ return !!GA_ID ? event(eventPayload) : undefined;