Skip to content

Commit 47dcd91

Browse files
updating snapshots
1 parent 7a2f329 commit 47dcd91

File tree

8 files changed

+363
-49
lines changed

8 files changed

+363
-49
lines changed

packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion.test.ts

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

packages/destination-actions/src/destinations/google-enhanced-conversions/__tests__/uploadClickConversion2.test.ts

Lines changed: 18 additions & 18 deletions
Large diffs are not rendered by default.

packages/destination-actions/src/destinations/google-enhanced-conversions/functions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ export function convertTimestamp(timestamp: string | undefined): string | undefi
219219
return timestamp.replace(/T/, ' ').replace(/(\.\d+)?Z/, '+00:00')
220220
}
221221

222+
export function timestampToEpochMicroseconds(timestamp: string): string | undefined {
223+
const date = new Date(timestamp)
224+
if (!isNaN(date.getTime())) {
225+
return (date.getTime() * 1000).toString()
226+
}
227+
return undefined
228+
}
229+
222230
export function getApiVersion(features?: Features, statsContext?: StatsContext): string {
223231
const statsClient = statsContext?.statsClient
224232
const tags = statsContext?.tags

packages/destination-actions/src/destinations/google-enhanced-conversions/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export interface ClickConversionRequestObjectInterface {
9494
gbraid: string | undefined
9595
wbraid: string | undefined
9696
userIpAddress?: string | undefined
97-
sessionAttributesEncoded: string | undefined
97+
sessionAttributesEncoded?: string
98+
sessionAttributesKeyValuePairs?: { [key: string]: string }
9899
orderId: string | undefined
99100
userIdentifiers: UserIdentifierInterface[]
100101
}

packages/destination-actions/src/destinations/google-enhanced-conversions/uploadClickConversion/generated-types.ts

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/destination-actions/src/destinations/google-enhanced-conversions/uploadClickConversion/index.ts

Lines changed: 129 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
getApiVersion,
2323
commonEmailValidation,
2424
getConversionActionDynamicData,
25-
formatPhone
25+
formatPhone,
26+
timestampToEpochMicroseconds
2627
} from '../functions'
2728
import { GOOGLE_ENHANCED_CONVERSIONS_BATCH_SIZE } from '../constants'
2829
import { processHashing } from '../../../lib/hashing-utils'
@@ -57,8 +58,7 @@ const action: ActionDefinition<Settings, Payload> = {
5758
},
5859
user_ip_address: {
5960
label: 'User IP Address',
60-
description:
61-
'The IP address of the user who initiated the conversion.',
61+
description: 'The IP address of the user who initiated the conversion.',
6262
type: 'string',
6363
default: {
6464
'@path': '$.context.ip'
@@ -67,12 +67,79 @@ const action: ActionDefinition<Settings, Payload> = {
6767
session_attributes_encoded: {
6868
label: 'Session Attributes (Encoded)',
6969
description:
70-
"A base64url-encoded JSON string containing session attributes collected from the user's browser. This provides additional attribution context if gclid, gbraid, or user identifiers are missing.",
70+
"A base64url-encoded JSON string containing session attributes collected from the user's browser. Provides additional attribution context if gclid, gbraid, or user identifiers are missing. ",
7171
type: 'string',
7272
default: {
7373
'@path': '$.integrations.Google Ads Conversions.session_attributes_encoded'
7474
}
7575
},
76+
session_attributes_key_value_pairs: {
77+
label: 'Session Attributes (Key Value Pairs)',
78+
description:
79+
"An alternative to the 'Session Attributes (Encoded)' field which can be used for Offline Conversions. If both 'Session Attributes (Encoded)' and 'Session Attributes (Key Value Pairs)' are provided, the encoded field takes precedence.",
80+
type: 'object',
81+
additionalProperties: false,
82+
defaultObjectUI: 'keyvalue',
83+
properties: {
84+
gad_source: {
85+
label: 'GAD Source',
86+
description:
87+
"An aggregate parameter served in the URL to identify the source of traffic originating from ads. See [Google's docs](https://support.google.com/google-ads/answer/16193746?sjid=2692215861659291994)",
88+
type: 'string'
89+
},
90+
gad_campaignid: {
91+
label: 'GAD Campaign ID',
92+
description:
93+
"The ID of the specific ad campaign that drove the ad click. See [Google's docs](https://support.google.com/google-ads/answer/16193746?sjid=2692215861659291994)",
94+
type: 'string'
95+
},
96+
landing_page_url: {
97+
label: 'Landing Page URL',
98+
description:
99+
'The full URL of the landing page on your website. This indicates the specific page the user first arrived on.',
100+
type: 'string'
101+
},
102+
session_start_time_usec: {
103+
label: 'Session Start Time',
104+
description:
105+
"The timestamp of when the user's session began on your website. This helps track the duration of user visits. The format should be a full ISO 8601 string containing microseconds.",
106+
type: 'string',
107+
format: 'date-time'
108+
},
109+
landing_page_referrer: {
110+
label: 'Landing Page Referrer',
111+
description:
112+
"The URL of the webpage that linked the user to your website. This helps understand the traffic sources leading to your site. See [Google's docs](https://support.google.com/google-ads/answer/2382957?sjid=658827203196258052)",
113+
type: 'string'
114+
},
115+
landing_page_user_agent: {
116+
label: 'Landing Page User Agent',
117+
description:
118+
"A string that identifies the user's browser and operating system. This information can be useful for understanding the technical environment of your users.",
119+
type: 'string'
120+
}
121+
},
122+
default: {
123+
gad_source: {
124+
'@path': '$.properties.gad_source'
125+
},
126+
gad_campaignid: {
127+
'@path': '$.properties.gad_campaignid'
128+
},
129+
landing_page_url: {
130+
'@path': '$.context.page.url'
131+
},
132+
session_start_time_usec: {
133+
'@path': '$.timestamp'
134+
},
135+
landing_page_referrer: {
136+
'@path': '$.context.page.referrer'
137+
},
138+
landing_page_user_agent: {
139+
'@path': '$.context.userAgent'
140+
}
141+
}
142+
},
76143
conversion_timestamp: {
77144
label: 'Conversion Timestamp',
78145
description:
@@ -291,14 +358,42 @@ const action: ActionDefinition<Settings, Payload> = {
291358
})
292359
}
293360

361+
const {
362+
session_attributes_encoded,
363+
session_attributes_key_value_pairs: {
364+
gad_source,
365+
gad_campaignid,
366+
landing_page_url,
367+
session_start_time_usec,
368+
landing_page_referrer,
369+
landing_page_user_agent
370+
} = {}
371+
} = payload
372+
373+
const sessionStartTimeUsec = session_start_time_usec
374+
? timestampToEpochMicroseconds(session_start_time_usec)
375+
: undefined
376+
377+
const sessionAttributesKeyValuePairs = {
378+
...(gad_source ? { gadSource: gad_source } : {}),
379+
...(gad_campaignid ? { gadCampaignId: gad_campaignid } : {}),
380+
...(landing_page_url ? { landingPageUrl: landing_page_url } : {}),
381+
...(sessionStartTimeUsec ? { sessionStartTimeUsec } : {}),
382+
...(landing_page_referrer ? { landingPageReferrer: landing_page_referrer } : {}),
383+
...(landing_page_user_agent ? { landingPageUserAgent: landing_page_user_agent } : {})
384+
}
385+
294386
const request_object: ClickConversionRequestObjectInterface = {
295387
conversionAction: `customers/${settings.customerId}/conversionActions/${payload.conversion_action}`,
296388
conversionDateTime: convertTimestamp(payload.conversion_timestamp),
297389
gclid: payload.gclid,
298390
gbraid: payload.gbraid,
299391
wbraid: payload.wbraid,
300392
userIpAddress: payload.user_ip_address,
301-
sessionAttributesEncoded: payload.session_attributes_encoded,
393+
...(session_attributes_encoded ? { sessionAttributesEncoded: session_attributes_encoded } : {}),
394+
...(!session_attributes_encoded && Object.keys(sessionAttributesKeyValuePairs).length > 0
395+
? { sessionAttributesKeyValuePairs }
396+
: {}),
302397
orderId: payload.order_id,
303398
conversionValue: payload.value,
304399
currencyCode: payload.currency,
@@ -399,14 +494,42 @@ const action: ActionDefinition<Settings, Payload> = {
399494
})
400495
}
401496

497+
const {
498+
session_attributes_encoded,
499+
session_attributes_key_value_pairs: {
500+
gad_source,
501+
gad_campaignid,
502+
landing_page_url,
503+
session_start_time_usec,
504+
landing_page_referrer,
505+
landing_page_user_agent
506+
} = {}
507+
} = payload
508+
509+
const sessionStartTimeUsec = session_start_time_usec
510+
? timestampToEpochMicroseconds(session_start_time_usec)
511+
: undefined
512+
513+
const sessionAttributesKeyValuePairs = {
514+
...(gad_source ? { gadSource: gad_source } : {}),
515+
...(gad_campaignid ? { gadCampaignId: gad_campaignid } : {}),
516+
...(landing_page_url ? { landingPageUrl: landing_page_url } : {}),
517+
...(sessionStartTimeUsec ? { sessionStartTimeUsec } : {}),
518+
...(landing_page_referrer ? { landingPageReferrer: landing_page_referrer } : {}),
519+
...(landing_page_user_agent ? { landingPageUserAgent: landing_page_user_agent } : {})
520+
}
521+
402522
const request_object: ClickConversionRequestObjectInterface = {
403523
conversionAction: `customers/${customerId}/conversionActions/${payload.conversion_action}`,
404524
conversionDateTime: convertTimestamp(payload.conversion_timestamp),
405525
gclid: payload.gclid,
406526
gbraid: payload.gbraid,
407527
wbraid: payload.wbraid,
408528
userIpAddress: payload.user_ip_address,
409-
sessionAttributesEncoded: payload.session_attributes_encoded,
529+
...(session_attributes_encoded ? { sessionAttributesEncoded: session_attributes_encoded } : {}),
530+
...(!session_attributes_encoded && Object.keys(sessionAttributesKeyValuePairs).length > 0
531+
? { sessionAttributesKeyValuePairs }
532+
: {}),
410533
orderId: payload.order_id,
411534
conversionValue: payload.value,
412535
currencyCode: payload.currency,

packages/destination-actions/src/destinations/google-enhanced-conversions/uploadClickConversion2/generated-types.ts

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)