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

Api version update and Business messanger support #38

Merged
merged 2 commits into from
Nov 14, 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
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
homepage: 'https://stape.io/'
versions:
- sha: 44b60bf1f406af83ee98144b192d43b6c052308c
changeNotes: Version update, Business messenger support
- sha: cddd6fe15a357fc2e8e7bc70d5d5b5f026c83795
changeNotes: Add EventEnhancement option
- sha: 6e567485dd161d2ca270b61c6da49280905b5b92
Expand Down
20 changes: 7 additions & 13 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (!fbp && data.generateFbp) {
fbp = 'fb.' + subDomainIndex + '.' + getTimestampMillis() + '.' + generateRandom(1000000000, 2147483647);
}

const apiVersion = '17.0';
const apiVersion = '18.0';
const postUrl = 'https://graph.facebook.com/v' + apiVersion + '/' + enc(data.pixelId) + '/events?access_token=' + enc(data.accessToken);
const mappedEventData = mapEvent(eventData, data);

Expand Down Expand Up @@ -192,6 +192,10 @@ function mapEvent(eventData, data) {
mappedData.app_data = {};
}

if (mappedData.action_source === 'business_messaging') {
mappedData.messaging_channel = data.messaging_channel;
}

if (eventData.page_location) mappedData.event_source_url = eventData.page_location;
if (eventData.user_agent) mappedData.user_data.client_user_agent = eventData.user_agent;

Expand Down Expand Up @@ -273,19 +277,9 @@ function hashData(key, value) {

function hashDataIfNeeded(mappedData) {
if (mappedData.user_data) {
const keysToHash = ['em', 'ph', 'ge', 'db', 'ln', 'fn', 'ct', 'st', 'zp', 'country'];
for (let key in mappedData.user_data) {
if (
key === 'em' ||
key === 'ph' ||
key === 'ge' ||
key === 'db' ||
key === 'ln' ||
key === 'fn' ||
key === 'ct' ||
key === 'st' ||
key === 'zp' ||
key === 'country'
) {
if (keysToHash.indexOf(key) !== -1) {
mappedData.user_data[key] = hashData(key, mappedData.user_data[key]);
}
}
Expand Down
66 changes: 53 additions & 13 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ ___TEMPLATE_PARAMETERS___
"value": "system_generated",
"displayValue": "System Generated"
},
{
"value": "business_messaging",
"displayValue": "Business Messaging"
},
{
"value": "other",
"displayValue": "Other"
Expand All @@ -212,6 +216,36 @@ ___TEMPLATE_PARAMETERS___
],
"defaultValue": "website"
},
{
"type": "SELECT",
"name": "messaging_channel",
"displayName": "Messaging Channel",
"macrosInSelect": false,
"selectItems": [
{
"value": "messenger",
"displayValue": "Messenger"
},
{
"value": "whatsapp",
"displayValue": "WhatsApp"
}
],
"simpleValueType": true,
"defaultValue": "messenger",
"enablingConditions": [
{
"paramName": "actionSource",
"paramValue": "business_messaging",
"type": "EQUALS"
}
],
"valueValidators": [
{
"type": "NON_EMPTY"
}
]
},
{
"type": "TEXT",
"name": "accessToken",
Expand Down Expand Up @@ -443,6 +477,18 @@ ___TEMPLATE_PARAMETERS___
{
"value": "madid",
"displayValue": "Mobile Advertiser ID"
},
{
"value": "page_id",
"displayValue": "Page ID"
},
{
"value": "page_scoped_user_id",
"displayValue": "Page Scoped User ID"
},
{
"value": "ctwa_clid",
"displayValue": "Ctwa clid"
}
]
},
Expand Down Expand Up @@ -664,7 +710,7 @@ if (!fbp && data.generateFbp) {
fbp = 'fb.' + subDomainIndex + '.' + getTimestampMillis() + '.' + generateRandom(1000000000, 2147483647);
}

const apiVersion = '17.0';
const apiVersion = '18.0';
const postUrl = 'https://graph.facebook.com/v' + apiVersion + '/' + enc(data.pixelId) + '/events?access_token=' + enc(data.accessToken);
const mappedEventData = mapEvent(eventData, data);

Expand Down Expand Up @@ -805,6 +851,10 @@ function mapEvent(eventData, data) {
mappedData.app_data = {};
}

if (mappedData.action_source === 'business_messaging') {
mappedData.messaging_channel = data.messaging_channel;
}

if (eventData.page_location) mappedData.event_source_url = eventData.page_location;
if (eventData.user_agent) mappedData.user_data.client_user_agent = eventData.user_agent;

Expand Down Expand Up @@ -886,19 +936,9 @@ function hashData(key, value) {

function hashDataIfNeeded(mappedData) {
if (mappedData.user_data) {
const keysToHash = ['em', 'ph', 'ge', 'db', 'ln', 'fn', 'ct', 'st', 'zp', 'country'];
for (let key in mappedData.user_data) {
if (
key === 'em' ||
key === 'ph' ||
key === 'ge' ||
key === 'db' ||
key === 'ln' ||
key === 'fn' ||
key === 'ct' ||
key === 'st' ||
key === 'zp' ||
key === 'country'
) {
if (keysToHash.indexOf(key) !== -1) {
mappedData.user_data[key] = hashData(key, mappedData.user_data[key]);
}
}
Expand Down
Loading