Skip to content

Commit

Permalink
[Browser] [GA4] Convert Consent Values to Lower Case (#2535)
Browse files Browse the repository at this point in the history
* Add dropdown for all privacy mappings

* Add lower case in storage consents

* Add unit test

* Add dropdowns
  • Loading branch information
harsh-joshi99 authored Nov 19, 2024
1 parent 3468c1f commit c209125
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
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

0 comments on commit c209125

Please sign in to comment.