-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): pull main into develop post release v1.82.2 (#3817)
- Loading branch information
Showing
34 changed files
with
755 additions
and
10,883 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const ENDPOINT = 'https://ct.pinterest.com/events/v3'; | ||
// ref: https://developers.pinterest.com/docs/api/v5/#tag/conversion_events | ||
const getV5EventsEndpoint = (adAccountId) => | ||
`https://api.pinterest.com/v5/ad_accounts/${adAccountId}/events`; | ||
|
||
const API_VERSION = { | ||
v3: 'legacyApi', | ||
v5: 'newApi', | ||
}; | ||
|
||
// ref: https://s.pinimg.com/ct/docs/conversions_api/dist/v3.html | ||
const MAX_BATCH_SIZE = 1000; | ||
|
||
module.exports = { | ||
ENDPOINT, | ||
MAX_BATCH_SIZE, | ||
getV5EventsEndpoint, | ||
API_VERSION, | ||
}; |
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 |
---|---|---|
|
@@ -3,8 +3,8 @@ bindings: | |
path: ../../../../constants | ||
- path: ../../bindings/jsontemplate | ||
exportAll: true | ||
- path: ../../../../v0/destinations/pinterest_tag/utils | ||
- path: ../../../../v0/destinations/pinterest_tag/config | ||
- path: ./utils | ||
- path: ./config | ||
- name: removeUndefinedValues | ||
path: ../../../../v0/util | ||
- name: removeUndefinedAndNullAndEmptyValues | ||
|
@@ -66,7 +66,10 @@ steps: | |
"opt_out": .context.device.adTrackingEnabled !== undefined ? !.context.device.adTrackingEnabled, | ||
"event_id": $.getOneByPaths(., ^.destination.Config.deduplicationKey) ?? .messageId, | ||
"app_id": ^.destination.Config.appId, | ||
"advertiser_id": ^.destination.Config.advertiserId | ||
"advertiser_id": ^.destination.Config.advertiserId, | ||
"partner_name": .properties.partnerName, | ||
"device_carrier": .context.network.carrier, | ||
"wifi": .context.network.wifi | ||
}); | ||
$.outputs.apiVersion === {{$.API_VERSION.v5}} ? commonFields = commonFields{~["advertiser_id"]}; | ||
$.removeUndefinedValues(commonFields) | ||
|
@@ -103,7 +106,8 @@ steps: | |
"client_ip_address": .context.ip ?? .request_ip, | ||
"client_user_agent": .context.userAgent, | ||
"external_id": {{{{$.getGenericPaths("userId")}}}}, | ||
"click_id": .properties.clickId | ||
"click_id": .properties.clickId, | ||
"partner_id": .traits.partnerId ?? .context.traits.partnerId | ||
}); | ||
!.destination.Config.sendExternalId ? userFields = userFields{~["external_id"]} : null; | ||
userFields = $.removeUndefinedAndNullAndEmptyValues(userFields); | ||
|
@@ -129,7 +133,11 @@ steps: | |
"num_items": .properties.numOfItems && Number(.properties.numOfItems), | ||
"order_id": .properties.order_id, | ||
"search_string": .properties.query, | ||
"opt_out_type": .properties.optOutType | ||
"opt_out_type": .properties.optOutType, | ||
"content_name": .properties.contentName, | ||
"content_category": .properties.contentCategory, | ||
"content_brand": .properties.contentBrand, | ||
"np": .properties.np | ||
}); | ||
$.removeUndefinedValues(customFields) | ||
|
@@ -143,7 +151,11 @@ steps: | |
"content_ids": products.(.product_id ?? .sku ?? .id)[], | ||
"contents": [email protected].({ | ||
"quantity": Number(.quantity ?? prop.quantity ?? 1), | ||
"item_price": String(.price ?? prop.price) | ||
"item_price": String(.price ?? prop.price), | ||
"item_name": String(.name), | ||
"id": .product_id ?? .sku, | ||
"item_category": .category, | ||
"item_brand": .brand | ||
})[] | ||
} | ||
else: | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* eslint-disable no-param-reassign */ | ||
const sha256 = require('sha256'); | ||
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib'); | ||
|
||
const { API_VERSION } = require('./config'); | ||
|
||
const VALID_ACTION_SOURCES = ['app_android', 'app_ios', 'web', 'offline']; | ||
|
||
const ecomEventMaps = [ | ||
{ | ||
src: ['order completed'], | ||
dest: 'checkout', | ||
}, | ||
{ | ||
src: ['product added'], | ||
dest: 'add_to_cart', | ||
}, | ||
{ | ||
src: ['products searched', 'product list filtered'], | ||
dest: 'search', | ||
}, | ||
]; | ||
|
||
const USER_NON_ARRAY_PROPERTIES = ['client_user_agent', 'client_ip_address']; | ||
|
||
const getHashedValue = (key, value) => { | ||
switch (key) { | ||
case 'em': | ||
case 'ct': | ||
case 'st': | ||
case 'country': | ||
case 'ln': | ||
case 'fn': | ||
case 'ge': | ||
value = Array.isArray(value) | ||
? value.map((val) => val.toString().trim().toLowerCase()) | ||
: value.toString().trim().toLowerCase(); | ||
break; | ||
case 'ph': | ||
// phone numbers should only contain digits & should not contain leading zeros | ||
value = Array.isArray(value) | ||
? value.map((val) => val.toString().replace(/\D/g, '').replace(/^0+/, '')) | ||
: value.toString().replace(/\D/g, '').replace(/^0+/, ''); | ||
break; | ||
case 'zp': | ||
// zip fields should only contain digits | ||
value = Array.isArray(value) | ||
? value.map((val) => val.toString().trim().replace(/\D/g, '')) | ||
: value.toString().replace(/\D/g, ''); | ||
break; | ||
case 'hashed_maids': | ||
case 'external_id': | ||
case 'db': | ||
// no action needed on value | ||
break; | ||
default: | ||
return String(value); | ||
} | ||
return Array.isArray(value) ? value.map((val) => sha256(val)) : [sha256(value)]; | ||
}; | ||
|
||
/** | ||
* | ||
* @param {*} userPayload Payload mapped from user fields | ||
* @returns | ||
* Further Processing the user fields following the instructions of Pinterest Conversion API | ||
* Ref: https://s.pinimg.com/ct/docs/conversions_api/dist/v3.html | ||
*/ | ||
const processUserPayload = (userPayload) => { | ||
Object.keys(userPayload).forEach((key) => { | ||
userPayload[key] = getHashedValue(key, userPayload[key]); | ||
}); | ||
return userPayload; | ||
}; | ||
|
||
/** | ||
* | ||
* @param {*} eventName // ["WatchVideo", "ViewCategory", "Custom"] | ||
* @returns // ["watch_video", "view_category", "custom""] | ||
* This function will return the snake case name of the destination config mapped event | ||
*/ | ||
const convertToSnakeCase = (eventName) => | ||
eventName.map((str) => | ||
str | ||
.replace(/([a-z])([A-Z])/g, '$1_$2') | ||
.replace(/\s+/g, '_') | ||
.toLowerCase(), | ||
); | ||
|
||
/** | ||
* | ||
* @param {*} userPayload | ||
* @param {*} message | ||
* @returns converts every single hashed user data property to array, except for | ||
* "client_user_agent", "client_ip_address" | ||
* | ||
*/ | ||
const processHashedUserPayload = (userPayload, message) => { | ||
const processedHashedUserPayload = {}; | ||
Object.keys(userPayload).forEach((key) => { | ||
if (!USER_NON_ARRAY_PROPERTIES.includes(key)) { | ||
if (Array.isArray(userPayload[key])) { | ||
processedHashedUserPayload[key] = [...userPayload[key]]; | ||
} else { | ||
processedHashedUserPayload[key] = [userPayload[key]]; | ||
} | ||
} else { | ||
processedHashedUserPayload[key] = userPayload[key]; | ||
} | ||
}); | ||
// multiKeyMap will works on only specific values like m, male, MALE, f, F, Female | ||
// if hashed data is sent from the user, it is directly set over here | ||
const gender = message.traits?.gender || message.context?.traits?.gender; | ||
if (gender && Array.isArray(gender)) { | ||
processedHashedUserPayload.ge = [...gender]; | ||
} else if (gender) { | ||
processedHashedUserPayload.ge = [gender]; | ||
} | ||
return processedHashedUserPayload; | ||
}; | ||
|
||
const validateInput = (message, { Config }) => { | ||
const { apiVersion = API_VERSION.v3, advertiserId, adAccountId, conversionToken } = Config; | ||
if (apiVersion === API_VERSION.v3 && !advertiserId) { | ||
throw new ConfigurationError('Advertiser Id not found. Aborting'); | ||
} | ||
|
||
if (apiVersion === API_VERSION.v5) { | ||
if (!adAccountId) { | ||
throw new ConfigurationError('Ad Account ID not found. Aborting'); | ||
} | ||
|
||
if (!conversionToken) { | ||
throw new ConfigurationError('Conversion Token not found. Aborting'); | ||
} | ||
} | ||
|
||
if (!message.type) { | ||
throw new InstrumentationError('Event type is required'); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
processUserPayload, | ||
processHashedUserPayload, | ||
VALID_ACTION_SOURCES, | ||
ecomEventMaps, | ||
convertToSnakeCase, | ||
validateInput, | ||
}; |
2 changes: 1 addition & 1 deletion
2
.../destinations/pinterest_tag/utils.test.js → .../destinations/pinterest_tag/utils.test.js
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
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
src/v0/destinations/pinterest_tag/data/pinterestCommonConfig.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.