REST API /cart/add.js not triggering Facebook Conversions API AddToCart events

smi
New Member
3 0 0

Hey community,

we enabled the Shopify / Facebook Conversions API integration and everything seems to work smoothly (ViewContent, InitiateCheckout, Purchase events etc), except we are lacking server-side AddToCart events. Our theme uses the REST api /cart/add.js and update.js. But those endpoints do not seem to trigger Conversion API events (see screenshot attached).

Screenshot 2021-07-13 at 11.02.58.png

Anyone with same issues and a workaround?

This is our code how we add items to the cart via the REST api:

var xhr = new XMLHttpRequest();
var payload = { updates: {} };

payload.updates[id] = 1;
xhr.open('POST', '/cart/update.js', true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.onload = function () {
  cart = JSON.parse(this.response);
  callback(cart);
};
xhr.send(JSON.stringify( payload ));

Cheers from Berlin, Sebastian

0 Likes
Jayvin
Shopify Partner
217 34 57

Hi,

Since you are doing something custom for adding products to your cart. You need to track the FB 'AddToCart' event in your script.

 

 

// your callback should track the event if the product has been added successfully
function callback(cart){
     fbq('track', 'AddToCart', {
        content_name: 'YOUR PRODUCT TITLE', 
        content_category: 'YOUR PRODUCT CATEGORY',
        content_ids: ['VARIANT_ID OR PRODUCT_ID'], // do some research
        content_type: 'product',
        value: PRICE OF YOUR PRODUCT,
        currency: CURRENCY
      });
}

 

Note this is just an example of a solution of how you can do it, don't just copy paste this code.

 

0 Likes
smi
New Member
3 0 0

Thanks Jayvin,

the solution you provided does client-side tracking (browser) which we already implemented (and which works).

I asked about the server-side version of tracking AddToCart events which tracks data to the Facebook server via the Facebook Conversions Api (CAPI). Shopify rolled this out several weeks ago. It works like expected for page views and checkouts - but not for "AddToCart" events on this endpoint.

Regards

0 Likes
motiv
Tourist
10 0 1

Have you noticed any discrepancy between the numbers you see on Shopify and what you are tracking on FB?

I am trying to resolve this tracking issue with the FB app and see what other ways provide a better and more accurate solution.

0 Likes
smi
New Member
3 0 0

Yes, the numbers on Facebook Ad Manager are completely off due to shorter attribution windows. We are using UTM paramaters to get more accurate data on Google Analytics, but those seem off also.

That's why we rely on server-side tracking - but the Shopify solution does not work using the REST endpoint.

0 Likes