зеркало из https://github.com/mozilla/fxa.git
feat(payments): google analytics deny consent
Because: * SubPlat currently does not request cookie consent from customers, therefore Google Analytics should be configured to not use any cookies. This commit: * Sets Google Analytics default consent to denied for all consent types. * Renames testMode to debugMode, and reassigned it to the gtag debug_mode option, which is what it was originally intended for. Closes #FXA-8445
This commit is contained in:
Родитель
128357cca7
Коммит
0aafc34a78
|
@ -117,9 +117,9 @@ const conf = convict({
|
||||||
env: 'GA_SUPPORTED_STRIPE_PRODUCT_IDS',
|
env: 'GA_SUPPORTED_STRIPE_PRODUCT_IDS',
|
||||||
format: String,
|
format: String,
|
||||||
},
|
},
|
||||||
testMode: {
|
debugMode: {
|
||||||
default: false,
|
default: false,
|
||||||
doc: 'Toggle Google Analytics test/debug mode',
|
doc: 'Toggle Google Analytics gtag debug mode. (Not to be confused with librayr react-ga testMode',
|
||||||
env: 'GA_TEST_MODE',
|
env: 'GA_TEST_MODE',
|
||||||
format: Boolean,
|
format: Boolean,
|
||||||
},
|
},
|
||||||
|
|
|
@ -73,7 +73,7 @@ module.exports = () => {
|
||||||
enabled: config.get('googleAnalytics.enabled'),
|
enabled: config.get('googleAnalytics.enabled'),
|
||||||
measurementId: config.get('googleAnalytics.measurementId'),
|
measurementId: config.get('googleAnalytics.measurementId'),
|
||||||
supportedProductIds: config.get('googleAnalytics.supportedProductIds'),
|
supportedProductIds: config.get('googleAnalytics.supportedProductIds'),
|
||||||
testMode: config.get('googleAnalytics.testMode'),
|
debugMode: config.get('googleAnalytics.debugMode'),
|
||||||
},
|
},
|
||||||
legalDocLinks: {
|
legalDocLinks: {
|
||||||
privacyNotice: config.get('legalDocLinks.privacyNotice'),
|
privacyNotice: config.get('legalDocLinks.privacyNotice'),
|
||||||
|
|
|
@ -123,7 +123,7 @@ const expectedMergedConfig = {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
measurementId: '',
|
measurementId: '',
|
||||||
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
||||||
testMode: false,
|
debugMode: false,
|
||||||
},
|
},
|
||||||
lang: '',
|
lang: '',
|
||||||
legalDocLinks: {
|
legalDocLinks: {
|
||||||
|
|
|
@ -7,7 +7,7 @@ export interface Config {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
measurementId: string;
|
measurementId: string;
|
||||||
supportedProductIds: string;
|
supportedProductIds: string;
|
||||||
testMode: boolean;
|
debugMode: boolean;
|
||||||
};
|
};
|
||||||
lang: string;
|
lang: string;
|
||||||
legalDocLinks: {
|
legalDocLinks: {
|
||||||
|
@ -61,7 +61,7 @@ export function defaultConfig(): Config {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
measurementId: '',
|
measurementId: '',
|
||||||
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
||||||
testMode: false,
|
debugMode: false,
|
||||||
},
|
},
|
||||||
lang: '',
|
lang: '',
|
||||||
legalDocLinks: {
|
legalDocLinks: {
|
||||||
|
|
|
@ -112,7 +112,7 @@ describe('useReactGA4Setup', () => {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
measurementId: '123',
|
measurementId: '123',
|
||||||
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
supportedProductIds: 'prod_GqM9ToKK62qjkK',
|
||||||
testMode: false,
|
debugMode: false,
|
||||||
},
|
},
|
||||||
} as Config;
|
} as Config;
|
||||||
const Subject = ({
|
const Subject = ({
|
||||||
|
@ -209,7 +209,9 @@ describe('useReactGA4Setup', () => {
|
||||||
config.googleAnalytics.measurementId,
|
config.googleAnalytics.measurementId,
|
||||||
{
|
{
|
||||||
nonce: '',
|
nonce: '',
|
||||||
testMode: config.googleAnalytics.testMode,
|
gtagOptions: {
|
||||||
|
debug_mode: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
||||||
|
@ -230,17 +232,19 @@ describe('useReactGA4Setup', () => {
|
||||||
config.googleAnalytics.measurementId,
|
config.googleAnalytics.measurementId,
|
||||||
{
|
{
|
||||||
nonce: '',
|
nonce: '',
|
||||||
testMode: config.googleAnalytics.testMode,
|
gtagOptions: {
|
||||||
|
debug_mode: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('successfully initialize ReactGA4 - with testMode enabled', () => {
|
it('successfully initialize ReactGA4 - with debugMode enabled', () => {
|
||||||
const config = {
|
const config = {
|
||||||
googleAnalytics: {
|
googleAnalytics: {
|
||||||
...mockConfig.googleAnalytics,
|
...mockConfig.googleAnalytics,
|
||||||
testMode: true,
|
debugMode: true,
|
||||||
},
|
},
|
||||||
} as Config;
|
} as Config;
|
||||||
const { queryByTestId } = renderWithLocalizationProvider(
|
const { queryByTestId } = renderWithLocalizationProvider(
|
||||||
|
@ -251,7 +255,9 @@ describe('useReactGA4Setup', () => {
|
||||||
config.googleAnalytics.measurementId,
|
config.googleAnalytics.measurementId,
|
||||||
{
|
{
|
||||||
nonce: '',
|
nonce: '',
|
||||||
testMode: true,
|
gtagOptions: {
|
||||||
|
debug_mode: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
expect(queryByTestId('success')?.textContent).toEqual('Render success');
|
||||||
|
|
|
@ -117,7 +117,7 @@ export function usePaypalButtonSetup(
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useReactGA4Setup(config: Config, productId: string) {
|
export function useReactGA4Setup(config: Config, productId: string) {
|
||||||
const { enabled, measurementId, supportedProductIds, testMode } =
|
const { enabled, measurementId, supportedProductIds, debugMode } =
|
||||||
config.googleAnalytics;
|
config.googleAnalytics;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -138,14 +138,26 @@ export function useReactGA4Setup(config: Config, productId: string) {
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Deny all consent types to disable cookies
|
||||||
|
// https://developers.google.com/tag-platform/devguides/privacy#consent_mode_terminology
|
||||||
|
ReactGA.gtag('consent', 'default', {
|
||||||
|
ad_storage: 'denied',
|
||||||
|
analytics_storage: 'denied',
|
||||||
|
functionality_storage: 'denied',
|
||||||
|
personalization_storage: 'denied',
|
||||||
|
security_storage: 'denied',
|
||||||
|
});
|
||||||
|
|
||||||
ReactGA.initialize(measurementId, {
|
ReactGA.initialize(measurementId, {
|
||||||
nonce: cspNonce,
|
nonce: cspNonce,
|
||||||
testMode,
|
gtagOptions: {
|
||||||
|
debug_mode: debugMode,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error initializing GA script\n', error);
|
console.error('Error initializing GA script\n', error);
|
||||||
}
|
}
|
||||||
}, [enabled, measurementId, supportedProductIds, testMode, productId]);
|
}, [enabled, measurementId, supportedProductIds, debugMode, productId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum CouponInfoBoxMessageType {
|
export const enum CouponInfoBoxMessageType {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче