Skip to content
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

[Browser] [GA4] Convert Consent Values to Lower Case #2535

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -806,4 +806,36 @@ describe('Set Configuration Fields action', () => {
send_page_view: false
})
})

it('should convert consent values to lower case', async () => {
defaultSettings.enableConsentMode = true

const [setConfigurationEventPlugin] = await googleAnalytics4Web({
...defaultSettings,
subscriptions
})
setConfigurationEvent = setConfigurationEventPlugin
await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)

const context = new Context({
event: 'setConfigurationFields',
type: 'page',
properties: {
ads_storage_consent_state: 'GRANTED',
analytics_storage_consent_state: 'Granted'
}
})

setConfigurationEvent.page?.(context)

expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted'
})
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
description:
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
label: 'Ads Storage Consent State',
type: 'string'
type: 'string',
choices: [
{ label: 'Granted', value: 'granted' },
{ label: 'Denied', value: 'denied' }
],
default: undefined
},
analytics_storage_consent_state: {
description:
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
label: 'Analytics Storage Consent State',
type: 'string'
type: 'string',
choices: [
{ label: 'Granted', value: 'granted' },
{ label: 'Denied', value: 'denied' }
],
default: undefined
},
ad_user_data_consent_state: {
description:
Expand Down Expand Up @@ -140,10 +150,10 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
ad_personalization?: ConsentParamsArg
} = {}
if (payload.ads_storage_consent_state) {
consentParams.ad_storage = payload.ads_storage_consent_state as ConsentParamsArg
consentParams.ad_storage = payload.ads_storage_consent_state.toLowerCase() as ConsentParamsArg
}
if (payload.analytics_storage_consent_state) {
consentParams.analytics_storage = payload.analytics_storage_consent_state as ConsentParamsArg
consentParams.analytics_storage = payload.analytics_storage_consent_state.toLowerCase() as ConsentParamsArg
}
if (payload.ad_user_data_consent_state) {
consentParams.ad_user_data = payload.ad_user_data_consent_state as ConsentParamsArg
Expand Down
Loading