Skip to content

Commit

Permalink
Update request based on latest data contract (#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlliterativeAlice authored Mar 19, 2024
1 parent 84a4e95 commit ae1d901
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,26 @@ const expectedProduct = {
product_name: mockProduct.name
}

const defaultExpectedConversionArgs = {
action: 'Test Event',
utm_source: mockUtmSource,
user_id: mockUserId,
first_name: mockFirstName,
last_name: mockLastName,
email: mockEmail,
phone: mockPhone
}

const defaultExpectedParams = {
segment_ss: '1',
event_type: 'identify',
title: mockPageTitle,
url: mockPageUrl,
ref: mockReferrer,
ip_fwd: mockIpAddress,
utm_source: mockUtmSource,
user_id: mockUserId,
first_name: mockFirstName,
last_name: mockLastName,
email: mockEmail,
phone: mockPhone,
ua_fwd: mockUserAgent,
uid: mockPixelId,
args: `{"action":"Test Event"}`
args: JSON.stringify(defaultExpectedConversionArgs)
}

const defaultEventPayload: Partial<SegmentEvent> = {
Expand Down Expand Up @@ -162,6 +167,7 @@ describe('StackAdapt', () => {
const requestParams = Object.fromEntries(new URL(responses[0].request.url).searchParams)
expect(requestParams).toEqual(expectedParams)
expect(JSON.parse(requestParams.args)).toEqual({
...defaultExpectedConversionArgs,
action: mockSingleProductAction,
revenue: mockRevenue,
order_id: mockOrderId,
Expand Down Expand Up @@ -202,6 +208,7 @@ describe('StackAdapt', () => {
const requestParams = Object.fromEntries(new URL(responses[0].request.url).searchParams)
expect(requestParams).toEqual(expectedParams)
expect(JSON.parse(requestParams.args)).toEqual({
...defaultExpectedConversionArgs,
action: mockMultiProductAction,
revenue: mockRevenue,
order_id: mockOrderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,15 @@ const action: ActionDefinition<Settings, Payload> = {
}

function getAvailableData(payload: Payload, settings: Settings) {
const ecommerceData = {
const conversionArgs = {
...payload.ecommerce_data,
...(!isEmpty(payload.ecommerce_products) && { products: payload.ecommerce_products })
...(!isEmpty(payload.ecommerce_products) && { products: payload.ecommerce_products }),
utm_source: payload.utm_source ?? '',
user_id: payload.user_id,
first_name: payload.first_name,
last_name: payload.last_name,
email: payload.email,
phone: payload.phone
}
return {
segment_ss: '1',
Expand All @@ -263,14 +269,9 @@ function getAvailableData(payload: Payload, settings: Settings) {
url: payload.url ?? '',
ref: payload.referrer ?? '',
ip_fwd: payload.ip_fwd ?? '',
utm_source: payload.utm_source ?? '',
user_id: payload.user_id,
ua_fwd: payload.user_agent ?? '',
uid: settings.pixelId,
first_name: payload.first_name ?? '',
last_name: payload.last_name ?? '',
email: payload.email ?? '',
phone: payload.phone ?? '',
...(!isEmpty(ecommerceData) && { args: JSON.stringify(ecommerceData) })
...(!isEmpty(conversionArgs) && { args: JSON.stringify(conversionArgs) })
}
}

Expand Down

0 comments on commit ae1d901

Please sign in to comment.