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

Google ads v11 to v12 #1018

Merged
merged 18 commits into from
Feb 15, 2023
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
@@ -1,28 +1,28 @@
export interface ProductItem {
item_id?: string
varadarajan-tw marked this conversation as resolved.
Show resolved Hide resolved
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.')
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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.')
}
})
})
})
Loading