Skip to content

Commit

Permalink
[MAIN] [STRATCONN] 3313 add page view field in setConfigurationFields (
Browse files Browse the repository at this point in the history
…#1904)

* send_page_view mapping added

* updated unit test cases of send_page_view in setConfigurationFields

* removed unrelevent code

* removed unrelevent code
  • Loading branch information
AnkitSegment authored Mar 4, 2024
1 parent 7662a18 commit 8d3a139
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const subscriptions: Subscription[] = [
},
ad_personalization_consent_state: {
'@path': '$.properties.ad_personalization_consent_state'
},
send_page_view: {
'@path': '$.properties.send_page_view'
}
}
}
Expand Down Expand Up @@ -118,7 +121,8 @@ describe('Set Configuration Fields action', () => {
})
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false
allow_google_signals: false,
send_page_view: true
})
})
it('should configure cookie expiry time other then default value', async () => {
Expand All @@ -144,6 +148,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
cookie_expires: 500
})
})
Expand Down Expand Up @@ -171,6 +176,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
cookie_domain: 'example.com'
})
})
Expand All @@ -197,6 +203,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
cookie_prefix: 'stage'
})
})
Expand Down Expand Up @@ -224,6 +231,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
cookie_path: '/home'
})
})
Expand All @@ -250,6 +258,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
cookie_update: false
})
})
Expand All @@ -274,7 +283,8 @@ describe('Set Configuration Fields action', () => {
setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false
allow_google_signals: false,
send_page_view: true
})
})
it('should update config if payload has screen resolution', () => {
Expand All @@ -290,6 +300,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
screen_resolution: '800*600'
})
})
Expand All @@ -306,6 +317,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
user_id: 'segment-123'
})
})
Expand All @@ -322,6 +334,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
page_title: 'User Registration Page'
})
})
Expand All @@ -338,6 +351,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
language: 'EN'
})
})
Expand All @@ -354,6 +368,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
content_group: '/home/login'
})
})
Expand All @@ -370,6 +385,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_term: 'running+shoes'
})
})
Expand All @@ -386,6 +402,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_source: 'google'
})
})
Expand All @@ -402,6 +419,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_name: 'spring_sale'
})
})
Expand All @@ -418,6 +436,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_medium: 'cpc'
})
})
Expand All @@ -434,6 +453,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_id: 'abc.123'
})
})
Expand All @@ -450,6 +470,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true,
campaign_content: 'logolink'
})
})
Expand All @@ -476,7 +497,8 @@ describe('Set Configuration Fields action', () => {
setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false
allow_google_signals: false,
send_page_view: true
})
})
it('should update config if payload has send_page_view is false', async () => {
Expand All @@ -502,7 +524,7 @@ describe('Set Configuration Fields action', () => {
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: false
send_page_view: true
})
})
it('should update config if payload has send_page_view is undefined', async () => {
Expand Down Expand Up @@ -615,4 +637,52 @@ describe('Set Configuration Fields action', () => {
setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {})
})
it('should update config if payload has send_page_view undefined', () => {
const context = new Context({
event: 'setConfigurationFields',
type: 'page',
properties: {
send_page_view: undefined
}
})

setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true
})
})
it('should update config if payload has send_page_view true', () => {
const context = new Context({
event: 'setConfigurationFields',
type: 'page',
properties: {
send_page_view: true
}
})

setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false
})
})

it('should update config if payload has send_page_view false', () => {
const context = new Context({
event: 'setConfigurationFields',
type: 'page',
properties: {
send_page_view: false
}
})

setConfigurationEvent.page?.(context)
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: false
})
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
label: 'Screen Resolution',
type: 'string'
},
send_page_view: {
description: 'Set to false to prevent sending a page_view.',
label: 'Send Page Views',
type: 'boolean',
choices: [
{ label: 'True', value: 'true' },
{ label: 'False', value: 'false' }
],
default: true
},
params: params
},
perform: (gtag, { payload, settings }) => {
Expand All @@ -142,7 +152,6 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
consentParams.ad_personalization = payload.ad_personalization_consent_state as ConsentParamsArg
}
gtag('consent', 'update', consentParams)

}
type ConfigType = { [key: string]: unknown }

Expand Down Expand Up @@ -170,6 +179,10 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
if (settings.pageView != true) {
config.send_page_view = settings.pageView ?? true
}

if (payload.send_page_view != true) {
config.send_page_view = payload.send_page_view ?? true
}
if (settings.cookieFlags) {
config.cookie_flags = settings.cookieFlags
}
Expand Down

0 comments on commit 8d3a139

Please sign in to comment.