Skip to content

Commit f1229f0

Browse files
committed
ADO-313: retains existing logic for events on cacheble pages
1 parent 4709694 commit f1229f0

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

app/code/Meta/Conversion/view/frontend/web/js/metaPixelTracker.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ define([
55
], function ($, customerData) {
66
'use strict';
77

8-
const capiEvents = [
8+
const nonCachedCapiEvents = [
99
'facebook_businessextension_ssapi_add_to_cart',
1010
'facebook_businessextension_ssapi_initiate_checkout',
1111
'facebook_businessextension_ssapi_add_payment_info',
@@ -37,17 +37,33 @@ define([
3737
track = config.browserEventData.track,
3838
event = config.browserEventData.event,
3939
pixelEventPayload = config.browserEventData.payload,
40-
eventId = config.payload.eventId;
40+
eventId = config.payload.eventId,
41+
trackServerEventUrl = config.url,
42+
serverEventPayload = config.payload;
4143

4244
fbq('set', 'agent', agent, pixelId);
4345
fbq(track, event, pixelEventPayload, {
4446
eventID: eventId
4547
});
48+
// trigger server-side CAPI event for cached pages
49+
if (!nonCachedCapiEvents.includes(config.payload.eventName)) {
50+
$.ajax({
51+
showLoader: true,
52+
url: trackServerEventUrl,
53+
type: 'POST',
54+
data: serverEventPayload,
55+
dataType: 'json',
56+
global: false,
57+
error: function (error) {
58+
console.log(error);
59+
}
60+
});
61+
}
4662
}
4763

4864
return function (config) {
4965
if (!config.payload.eventId) {
50-
if (capiEvents.includes(config.payload.eventName)) {
66+
if (nonCachedCapiEvents.includes(config.payload.eventName)) {
5167
var eventIds = customerData.get('capi-event-ids')
5268
eventIds.subscribe(function (eventIds) {
5369
let eventIdsFromSection = customerData.get('capi-event-ids')();

0 commit comments

Comments
 (0)