Currently working on creating a custom JavaScript function to convert the JSON formatted track event into the corresponding Facebook Pixel event.
The track event is placed on an e-commerce site as shown below:
analytics.track('Product List Viewed', {
category: 'Deals',
list_id: 'hot_deals_1',
products: [
{
category: 'Games',
image_url: 'https://www.example.com/product/path.jpg',
name: 'Monopoly: 3rd Edition',
position: 1,
price: 19,
product_id: '507f1f77bcf86cd799439011',
sku: '45790-32',
url: 'https://www.example.com/product/path'
},
{
category: 'Games',
name: 'Uno Card Game',
position: 2,
price: 3,
product_id: '505bd76785ebb509fc183733',
sku: '46493-32'
}
]
});
The JavaScript event described above is implemented on a website to gather details about a user's viewed Product List. The raw JSON message of the event is sent as follows:
{
"anonymousId": "70bbe85a-97db-49da-b36f-419dd858f3be",
"context": {
"ip": "12.179.173.270",
"library": {
"name": "analytics.js",
"version": "3.8.2"
},
"page": {
"title": "Toys R Us",
"url": "https://toys-r-us.com"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36"
},
"event": "Product List Viewed",
"integrations": {},
"messageId": "ajs-515fef4d8615e8f95d88988d0cb77e60",
"originalTimestamp": "2019-06-18T17:16:11.546Z",
"properties": {
"category": "Deals",
"list_id": "hot_deals_1",
"products": [
{
"category": "Games",
"name": "Monopoly: 3rd Edition",
"position": 1,
"price": 19,
"product_id": "507f1f77bcf86cd799439011",
"sku": "45790-32",
"url": "https://www.example.com/product/path"
},
{
"category": "Games",
"name": "Uno Card Game",
"position": 2,
"price": 3,
"product_id": "505bd76785ebb509fc183733",
"sku": "46493-32"
}
]
},
"receivedAt": "2019-06-18T17:16:11.579Z",
"sentAt": "2019-06-18T17:16:11.554Z",
"timestamp": "2019-06-18T17:16:11.571Z",
"type": "track"
}
I am in the process of developing a JavaScript function to transform the raw JSON data into Facebook's fbq('track') function, converting the event into the equivalent ViewContent standard event on Facebook.
The expected output should resemble the following example, but I require assistance with constructing the JavaScript function to convert the JSON data into the desired format:
<script>
fbq('track', 'ViewContent', {content_name: ‘Monopoly: 3rd Edition’,
content_category: ‘Games’,
content_ids: ['45790-32'],
content_type: 'product',
value: 19,
currency: 'USD'
},
{
content_name: ‘Uno Card Game’,
content_category: ‘Games’,
content_ids: ['46493-32'],
content_type: 'product',
value: 3,
currency: 'USD'
}
);
</script>