|
5 | 5 | ], function ($, customerData) {
|
6 | 6 | 'use strict';
|
7 | 7 |
|
8 |
| - const capiEvents = [ |
| 8 | + const nonCachedCapiEvents = [ |
9 | 9 | 'facebook_businessextension_ssapi_add_to_cart',
|
10 | 10 | 'facebook_businessextension_ssapi_initiate_checkout',
|
11 | 11 | 'facebook_businessextension_ssapi_add_payment_info',
|
@@ -37,17 +37,33 @@ define([
|
37 | 37 | track = config.browserEventData.track,
|
38 | 38 | event = config.browserEventData.event,
|
39 | 39 | pixelEventPayload = config.browserEventData.payload,
|
40 |
| - eventId = config.payload.eventId; |
| 40 | + eventId = config.payload.eventId, |
| 41 | + trackServerEventUrl = config.url, |
| 42 | + serverEventPayload = config.payload; |
41 | 43 |
|
42 | 44 | fbq('set', 'agent', agent, pixelId);
|
43 | 45 | fbq(track, event, pixelEventPayload, {
|
44 | 46 | eventID: eventId
|
45 | 47 | });
|
| 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 | + } |
46 | 62 | }
|
47 | 63 |
|
48 | 64 | return function (config) {
|
49 | 65 | if (!config.payload.eventId) {
|
50 |
| - if (capiEvents.includes(config.payload.eventName)) { |
| 66 | + if (nonCachedCapiEvents.includes(config.payload.eventName)) { |
51 | 67 | var eventIds = customerData.get('capi-event-ids')
|
52 | 68 | eventIds.subscribe(function (eventIds) {
|
53 | 69 | let eventIdsFromSection = customerData.get('capi-event-ids')();
|
|
0 commit comments