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

fix: linkedin ads conversionValue object as well as price is not mandatory #3860

Merged
merged 2 commits into from
Nov 11, 2024
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
6 changes: 2 additions & 4 deletions src/cdk/v2/destinations/linkedin_ads/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function checkIfPricePresent(properties) {
}

const calculateConversionObject = (message) => {
const { properties, event } = message;
const { properties } = message;

const calculateAmount = () => {
if (properties?.products && properties.products.length > 0) {
Expand All @@ -107,9 +107,7 @@ const calculateConversionObject = (message) => {
};
return conversionObject;
}
throw new InstrumentationError(
`[LinkedIn Conversion API]: Cannot map price for event ${event}. Aborting`,
);
return null;
};

const deduceConversionRules = (trackEventName, destConfig) => {
Expand Down
9 changes: 5 additions & 4 deletions src/cdk/v2/destinations/linkedin_ads/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ describe('formatEmail', () => {
});

describe('calculateConversionObject', () => {
// Returns a conversion object with currency code 'USD' and amount 0 when message properties are empty
it('should throw instrumentation error when message properties are empty', () => {
// Returns empty object when message properties are empty
it('should return empty object when message properties are empty', () => {
const message = { properties: {} };
expect(() => {
fetchUserIds(calculateConversionObject(message));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was fetchUserIds doing before ?

}).toThrow(InstrumentationError);
const conversionObject = calculateConversionObject(message);
expect(conversionObject).toEqual({});
});
});

// Returns a conversion object with currency code 'USD' and amount 0 when message properties price is defined but quantity is 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { generateMetadata, generateTrackPayload, overrideDestination } from '../../../testUtils';
import {
generateMetadata,
generateTrackPayload,
overrideDestination,
transformResultBuilder,
} from '../../../testUtils';
import { Destination } from '../../../../../src/types';
import { ProcessorTestData } from '../../../testTypes';

Expand Down Expand Up @@ -75,6 +80,14 @@ const commonStats = {
workspaceId: 'default-workspaceId',
};

const commonHeader = {
Authorization: 'Bearer default-accessToken',
'Content-Type': 'application/json',
Dismissed Show dismissed Hide dismissed
'LinkedIn-Version': '202402',
'X-RestLi-Method': 'BATCH_CREATE',
'X-Restli-Protocol-Version': '2.0.0',
};

const commonTimestamp = new Date('2023-10-14');
const olderTimestamp = new Date('2023-07-13');

Expand Down Expand Up @@ -234,7 +247,7 @@ export const validationTestData: ProcessorTestData[] = [
description: 'Track call : properties without product array and no price',
scenario: 'Business',
successCriteria:
'should throw error with status code 400 and error message regarding price is a mandatory field for linkedin conversions',
'should not have conversionValue object as price is a mandatory field for linkedin conversions',
feature: 'processor',
module: 'destination',
version: 'v0',
Expand All @@ -243,7 +256,7 @@ export const validationTestData: ProcessorTestData[] = [
body: [
{
message: generateTrackPayload({
event: 'random event',
event: 'ABC Searched',
properties: commonUserProperties,
context: {
traits: commonUserTraits,
Expand All @@ -264,11 +277,51 @@ export const validationTestData: ProcessorTestData[] = [
status: 200,
body: [
{
error:
'[LinkedIn Conversion API]: Cannot map price for event random event. Aborting: Workflow: procWorkflow, Step: commonFields, ChildStep: undefined, OriginalError: [LinkedIn Conversion API]: Cannot map price for event random event. Aborting',
output: transformResultBuilder({
version: '1',
type: 'REST',
method: 'POST',
endpoint: `https://api.linkedin.com/rest/conversionEvents`,
headers: commonHeader,
params: {},
FORM: {},
files: {},
JSON: {
elements: [
{
conversion: 'urn:lla:llaPartnerConversion:1234567',
conversionHappenedAt: 1697241600000,
eventId: '12345',
user: {
userIds: [
{
idType: 'SHA256_EMAIL',
idValue:
'48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08',
},
],
},
},
{
conversion: 'urn:lla:llaPartnerConversion:34567',
conversionHappenedAt: 1697241600000,
eventId: '12345',
user: {
userIds: [
{
idType: 'SHA256_EMAIL',
idValue:
'48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08',
},
],
},
},
],
},
userId: '',
}),
statusCode: 200,
metadata: generateMetadata(1),
statTags: commonStats,
statusCode: 400,
},
],
},
Expand All @@ -289,7 +342,7 @@ export const validationTestData: ProcessorTestData[] = [
body: [
{
message: generateTrackPayload({
event: 'random event',
event: 'ABC Searched',
properties: commonUserPropertiesWithProductWithoutPrice,
context: {
traits: commonUserTraits,
Expand All @@ -310,11 +363,51 @@ export const validationTestData: ProcessorTestData[] = [
status: 200,
body: [
{
error:
'[LinkedIn Conversion API]: Cannot map price for event random event. Aborting: Workflow: procWorkflow, Step: commonFields, ChildStep: undefined, OriginalError: [LinkedIn Conversion API]: Cannot map price for event random event. Aborting',
output: transformResultBuilder({
version: '1',
type: 'REST',
method: 'POST',
endpoint: `https://api.linkedin.com/rest/conversionEvents`,
headers: commonHeader,
params: {},
FORM: {},
files: {},
JSON: {
elements: [
{
conversion: 'urn:lla:llaPartnerConversion:1234567',
conversionHappenedAt: 1697241600000,
eventId: '12345',
user: {
userIds: [
{
idType: 'SHA256_EMAIL',
idValue:
'48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08',
},
],
},
},
{
conversion: 'urn:lla:llaPartnerConversion:34567',
conversionHappenedAt: 1697241600000,
eventId: '12345',
user: {
userIds: [
{
idType: 'SHA256_EMAIL',
idValue:
'48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08',
},
],
},
},
],
},
userId: '',
}),
statusCode: 200,
metadata: generateMetadata(1),
statTags: commonStats,
statusCode: 400,
},
],
},
Expand Down
Loading