-
Notifications
You must be signed in to change notification settings - Fork 390
feat: [UIE-9805] - Extract EUUID from /profile header and send to Adobe analytics #13229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
f6a73aa
ce9cfa2
1f715e9
4524e2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Added | ||
| --- | ||
|
|
||
| Extract EUUID from authenticated API calls at the interceptor level and share it with Adobe analytics through the page view event ([#13229](https://github.com/linode/manager/pull/13229)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,28 @@ | ||
| import { useProfile } from '@linode/queries'; | ||
| import { loadScript } from '@linode/utilities'; | ||
| import { useLocation } from '@tanstack/react-router'; | ||
| import React from 'react'; | ||
|
|
||
| import { ADOBE_ANALYTICS_URL } from 'src/constants'; | ||
| import { reportException } from 'src/exceptionReporting'; | ||
|
|
||
| import type { ExtendedProfile } from 'src/request'; | ||
|
|
||
| /** | ||
| * Initializes our Adobe Analytics script on mount and subscribes to page view events. | ||
| * The EUUID is read from the profile data (injected by the injectEuuidToProfile interceptor). | ||
| */ | ||
| export const useAdobeAnalytics = () => { | ||
| const location = useLocation(); | ||
| const { data: profile } = useProfile() as { | ||
| data: ExtendedProfile | undefined; | ||
| }; | ||
| const euuid = profile?._euuidFromHttpHeader; | ||
|
|
||
| React.useEffect(() => { | ||
| // Load Adobe Analytics Launch Script | ||
| // Note: The first page view may not include EUUID since the profile | ||
| // may not have loaded yet. Subsequent page views will include it. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? |
||
| if (ADOBE_ANALYTICS_URL) { | ||
| loadScript(ADOBE_ANALYTICS_URL, { location: 'head' }) | ||
| .then((data) => { | ||
|
|
@@ -26,6 +36,7 @@ export const useAdobeAnalytics = () => { | |
| // Fire the first page view for the landing page | ||
| window._satellite.track('page view', { | ||
| url: window.location.pathname, | ||
| ...(euuid && { euuid }), | ||
| }); | ||
| }) | ||
| .catch(() => { | ||
|
|
@@ -36,11 +47,13 @@ export const useAdobeAnalytics = () => { | |
|
|
||
| React.useEffect(() => { | ||
| /** | ||
| * Send pageviews when location changes | ||
| * Send pageviews when location changes. | ||
| * Includes EUUID (Enterprise UUID) if available from the profile response. | ||
| */ | ||
| if (window._satellite) { | ||
| window._satellite.track('page view', { | ||
| url: location.pathname, | ||
| ...(euuid && { euuid }), | ||
| }); | ||
| } | ||
| }, [location.pathname]); // Listen to location changes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,12 @@ | |
| import { AxiosHeaders } from 'axios'; | ||
|
|
||
| import { setAuthDataInLocalStorage } from './OAuth/oauth'; | ||
| import { getURL, handleError, injectAkamaiAccountHeader } from './request'; | ||
| import { | ||
| getURL, | ||
| handleError, | ||
| injectAkamaiAccountHeader, | ||
| injectEuuidToProfile, | ||
| } from './request'; | ||
| import { storeFactory } from './store'; | ||
| import { storage } from './utilities/storage'; | ||
|
|
||
|
|
@@ -106,3 +111,33 @@ | |
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('injectEuuidToProfile', () => { | ||
| const profile = profileFactory.build(); | ||
| const response: Partial<AxiosResponse> = { | ||
| data: profile, | ||
| status: 200, | ||
| config: { headers: new AxiosHeaders(), url: '/profile', method: 'get' }, | ||
| headers: { 'x-customer-uuid': '1234' }, | ||
| }; | ||
|
|
||
| it('injects the euuid on successful GET profile response ', () => { | ||
| const results = injectEuuidToProfile(response as any); | ||
|
Check warning on line 125 in packages/manager/src/request.test.tsx
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please strengthen your types. No |
||
| expect(results.data).toHaveProperty('_euuidFromHttpHeader', '1234'); | ||
| // eslint-disable-next-line | ||
| const { _euuidFromHttpHeader, ...originalData } = results.data; | ||
| expect(originalData).toEqual(profile); | ||
| }); | ||
|
|
||
| it('returns the original profile data if no header is present', () => { | ||
| const responseWithNoHeaders = { ...response, headers: {} }; | ||
| expect(injectEuuidToProfile(responseWithNoHeaders as any).data).toEqual( | ||
|
Check warning on line 134 in packages/manager/src/request.test.tsx
|
||
| profile | ||
| ); | ||
| }); | ||
|
|
||
| it("doesn't inject the euuid on other endpoints", () => { | ||
| const accountResponse = { ...response, config: { url: '/account' } }; | ||
| expect(injectEuuidToProfile(accountResponse as any).data).toEqual(profile); | ||
|
Check warning on line 141 in packages/manager/src/request.test.tsx
|
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ type DTMSatellite = { | |
| }; | ||
|
|
||
| interface PageViewPayload { | ||
| euuid?: string; | ||
| url: string; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we inject a property to the profile object, then it should be typed accordingly. No casting please