-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* gooogle conversion v12 upgrade * changes * bug fix for test cases * gooogle conversion v12 upgrade * changes * bug fix for test cases * flag name changes * flag name change in test cases * review changes * revert ga4-types file change * revert ga4-types file change * revert ga4-types file change --------- Co-authored-by: manoj kumar <[email protected]>
- Loading branch information
1 parent
b00de72
commit 1a7debb
Showing
9 changed files
with
517 additions
and
44 deletions.
There are no files selected for viewing
48 changes: 24 additions & 24 deletions
48
packages/browser-destinations/src/destinations/google-analytics-4-web/ga4-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
export interface ProductItem { | ||
item_id?: string | ||
item_name?: string | ||
affiliation?: string | ||
coupon?: string | ||
currency?: string | ||
discount?: number | ||
index?: number | ||
item_brand?: string | ||
item_category?: string | ||
item_category2?: string | ||
item_category3?: string | ||
item_category4?: string | ||
item_category5?: string | ||
item_list_id?: string | ||
item_list_name?: string | ||
item_variant?: string | ||
location_id?: string | ||
price?: number | ||
quantity?: number | ||
item_id?: string | ||
item_name?: string | ||
affiliation?: string | ||
coupon?: string | ||
currency?: string | ||
discount?: number | ||
index?: number | ||
item_brand?: string | ||
item_category?: string | ||
item_category2?: string | ||
item_category3?: string | ||
item_category4?: string | ||
item_category5?: string | ||
item_list_id?: string | ||
item_list_name?: string | ||
item_variant?: string | ||
location_id?: string | ||
price?: number | ||
quantity?: number | ||
} | ||
|
||
export interface PromotionProductItem extends ProductItem { | ||
creative_name?: string | ||
creative_slot?: string | ||
promotion_id?: string | ||
promotion_name?: string | ||
} | ||
creative_name?: string | ||
creative_slot?: string | ||
promotion_id?: string | ||
promotion_name?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,61 @@ describe('GoogleEnhancedConversions', () => { | |
expect(responses[1].status).toBe(201) | ||
}) | ||
|
||
it('uses v12 when google-enhanced-v12 flag is enabled', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
email: '[email protected]', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD' | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}/googleAds:searchStream`) | ||
.post('') | ||
.reply(200, [ | ||
{ | ||
results: [ | ||
{ | ||
conversionCustomVariable: { | ||
resourceName: 'customers/1234/conversionCustomVariables/123445', | ||
id: '123445', | ||
name: 'username' | ||
} | ||
} | ||
] | ||
} | ||
]) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadCallConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
const responses = await testDestination.testAction('uploadCallConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { | ||
conversion_action: '12345', | ||
caller_id: '+1234567890', | ||
call_timestamp: timestamp, | ||
custom_variables: { username: 'spongebob' } | ||
}, | ||
useDefaultMappings: true, | ||
settings: { | ||
customerId | ||
} | ||
}) | ||
|
||
expect(responses[1].options.body).toMatchInlineSnapshot( | ||
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"callerId\\":\\"+1234567890\\",\\"callStartDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\",\\"customVariables\\":[{\\"conversionCustomVariable\\":\\"customers/1234/conversionCustomVariables/123445\\",\\"value\\":\\"spongebob\\"}]}],\\"partialFailure\\":true}"` | ||
) | ||
|
||
expect(responses.length).toBe(2) | ||
expect(responses[1].status).toBe(201) | ||
}) | ||
|
||
it('fails if customerId not set', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
|
@@ -123,5 +178,67 @@ describe('GoogleEnhancedConversions', () => { | |
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.') | ||
} | ||
}) | ||
it('sends an event with default mappings', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
email: '[email protected]', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD' | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadCallConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
const responses = await testDestination.testAction('uploadCallConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345', caller_id: '+1234567890', call_timestamp: timestamp }, | ||
useDefaultMappings: true, | ||
settings: { | ||
customerId | ||
} | ||
}) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"callerId\\":\\"+1234567890\\",\\"callStartDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\"}],\\"partialFailure\\":true}"` | ||
) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
}) | ||
it('fails if customerId not set', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
email: '[email protected]', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD' | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadCallConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
try { | ||
await testDestination.testAction('uploadCallConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345', caller_id: '+1234567890', call_timestamp: timestamp }, | ||
useDefaultMappings: true, | ||
settings: {} | ||
}) | ||
fail('the test should have thrown an error') | ||
} catch (e) { | ||
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.') | ||
} | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,62 @@ describe('GoogleEnhancedConversions', () => { | |
expect(responses.length).toBe(2) | ||
expect(responses[1].status).toBe(201) | ||
}) | ||
it('uses v12 when google-enhanced-v12 flag is enabled', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
gclid: '54321', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '1234', | ||
quantity: 3, | ||
price: 10.99 | ||
} | ||
] | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}/googleAds:searchStream`) | ||
.post('') | ||
.reply(200, [ | ||
{ | ||
results: [ | ||
{ | ||
conversionCustomVariable: { | ||
resourceName: 'customers/1234/conversionCustomVariables/123445', | ||
id: '123445', | ||
name: 'username' | ||
} | ||
} | ||
] | ||
} | ||
]) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadClickConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
const responses = await testDestination.testAction('uploadClickConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345', custom_variables: { username: 'spongebob' } }, | ||
useDefaultMappings: true, | ||
settings: { | ||
customerId | ||
} | ||
}) | ||
|
||
expect(responses[1].options.body).toMatchInlineSnapshot( | ||
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"orderId\\":\\"1234\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\",\\"cartData\\":{\\"items\\":[{\\"productId\\":\\"1234\\",\\"quantity\\":3,\\"unitPrice\\":10.99}]},\\"userIdentifiers\\":[],\\"customVariables\\":[{\\"conversionCustomVariable\\":\\"customers/1234/conversionCustomVariables/123445\\",\\"value\\":\\"spongebob\\"}]}],\\"partialFailure\\":true}"` | ||
) | ||
|
||
expect(responses.length).toBe(2) | ||
expect(responses[1].status).toBe(201) | ||
}) | ||
|
||
it('fails if customerId not set', async () => { | ||
const event = createTestEvent({ | ||
|
@@ -183,5 +239,126 @@ describe('GoogleEnhancedConversions', () => { | |
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.') | ||
} | ||
}) | ||
it('sends an event with default mappings', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
gclid: '54321', | ||
email: '[email protected]', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '1234', | ||
quantity: 3, | ||
price: 10.99 | ||
} | ||
] | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadClickConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
const responses = await testDestination.testAction('uploadClickConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345' }, | ||
useDefaultMappings: true, | ||
settings: { | ||
customerId | ||
} | ||
}) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"orderId\\":\\"1234\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\",\\"cartData\\":{\\"items\\":[{\\"productId\\":\\"1234\\",\\"quantity\\":3,\\"unitPrice\\":10.99}]},\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"}]}],\\"partialFailure\\":true}"` | ||
) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
}) | ||
|
||
it('sends email and phone user_identifiers', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
gclid: '54321', | ||
email: '[email protected]', | ||
phone: '6161729102', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '1234', | ||
quantity: 3, | ||
price: 10.99 | ||
} | ||
] | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadClickConversions`) | ||
.post('') | ||
.reply(201, { results: [{}] }) | ||
|
||
const responses = await testDestination.testAction('uploadClickConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345' }, | ||
useDefaultMappings: true, | ||
settings: { | ||
customerId | ||
} | ||
}) | ||
|
||
expect(responses[0].options.body).toMatchInlineSnapshot( | ||
`"{\\"conversions\\":[{\\"conversionAction\\":\\"customers/1234/conversionActions/12345\\",\\"conversionDateTime\\":\\"2021-06-10 18:08:04+00:00\\",\\"orderId\\":\\"1234\\",\\"conversionValue\\":200,\\"currencyCode\\":\\"USD\\",\\"cartData\\":{\\"items\\":[{\\"productId\\":\\"1234\\",\\"quantity\\":3,\\"unitPrice\\":10.99}]},\\"userIdentifiers\\":[{\\"hashedEmail\\":\\"87924606b4131a8aceeeae8868531fbb9712aaa07a5d3a756b26ce0f5d6ca674\\"},{\\"hashedPhoneNumber\\":\\"1dba01a96da19f6df771cff07e0a8d822126709b82ae7adc6a3839b3aaa68a16\\"}]}],\\"partialFailure\\":true}"` | ||
) | ||
|
||
expect(responses.length).toBe(1) | ||
expect(responses[0].status).toBe(201) | ||
}) | ||
it('fails if customerId not set', async () => { | ||
const event = createTestEvent({ | ||
timestamp, | ||
event: 'Test Event', | ||
properties: { | ||
gclid: '54321', | ||
email: '[email protected]', | ||
orderId: '1234', | ||
total: '200', | ||
currency: 'USD', | ||
products: [ | ||
{ | ||
product_id: '1234', | ||
quantity: 3, | ||
price: 10.99 | ||
} | ||
] | ||
} | ||
}) | ||
|
||
nock(`https://googleads.googleapis.com/v12/customers/${customerId}:uploadClickConversions`) | ||
.post('') | ||
.reply(201, {}) | ||
|
||
try { | ||
await testDestination.testAction('uploadClickConversion', { | ||
event, | ||
features: { 'google-enhanced-v12': true }, | ||
mapping: { conversion_action: '12345' }, | ||
useDefaultMappings: true, | ||
settings: {} | ||
}) | ||
fail('the test should have thrown an error') | ||
} catch (e) { | ||
expect(e.message).toBe('Customer ID is required for this action. Please set it in destination settings.') | ||
} | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.