Purchase Event for Shopify

Hi, hope everyone is well.

Issue: GTM server purchase tag FAILED to fire.

Video Link to the issue:Loom | Free Screen & Video Recording Software

Shopify by default measures the purchase event using CAPI. however, I wanted to track the CAPI purchase event for a different FB pixel. Therefore, I took the Github code of GTM-server for Shopify and modify it to capture the purchase event.

 if (type === "Purchase") {
        dataLayer.push({
          event: type === "Purchase" ? "CAPI Purchase" : "Failed",
          event_id: eventId,
          price: parseInt(data["cd[value]"]),
          orderIds: data["cd[content_ids]"],
          itemCount: data["cd[num_items]"],
          currency: data["cd[currency]"],
          contentType: data["cd[content_type]"],
          customer_id: ShopifyAnalytics.meta.page.customerId
            ? ShopifyAnalytics.meta.page.customerId
            : "",
        });
      }

The code mentioned above works fine, it captures the data and sends it to the GTM server. Although everything looks fine on the server, the GTM server is failing to fire the purchase event, The error says

“code”:100,
“error_subcode”:2804009,

This is my GTM web container tag

This is my GTM server container tag

Hope the information provided was sufficient

-Hassan

Look like the issue with some parameter that you send to FB. I think with a content type. But to be sure please use this converter to decode error that you get in FB response Decode or Encode Unicode Text - Online Toolz

Hi, hope you are well. thank you for reaching back to me.

when i saw the video again, i find that the content_type was a a string “product_group” as shown in the screenshot below. and content_ids are also string.

I hardcoded the product_group in the parameters, though it didnt solve the issue. Can you recheck the video and see if there any another conclusion, that can be drawn

-Hassan

For future investigation, can you please decode the message that you receive from FB or paste it here as a text?

image

The issue was resolved.

The problem was in the event value, when I used the code, it parsed the integer, however, FB requires a float value… this is the new code

 if (type === "Purchase") {
        dataLayer.push({
          event: type === "Purchase" ? "CAPI Purchase" : "Failed",
          event_id: eventId,
          price: parseFloat((data["cd[value]"])).toFixed(2),
          orderIds: data["cd[content_ids]"],
          itemCount: parseInt(data["cd[num_items]"]),
          currency: data["cd[currency]"],
          contentType: data["cd[content_type]"],
          customer_id: ShopifyAnalytics.meta.page.customerId
            ? ShopifyAnalytics.meta.page.customerId
            : "",
        });
      }



1 Like

Hello All,
How do i track purchase for shopify site. using the the following code-

if (type === “Purchase”) {
dataLayer.push({
event: type === “Purchase” ? “CAPI Purchase” : “Failed”,
event_id: eventId,
price: parseFloat((data[“cd[value]”])).toFixed(2),
orderIds: data[“cd[content_ids]”],
itemCount: parseInt(data[“cd[num_items]”]),
currency: data[“cd[currency]”],
contentType: data[“cd[content_type]”],
customer_id: ShopifyAnalytics.meta.page.customerId
? ShopifyAnalytics.meta.page.customerId
: “”,
});
}

can anyone explain me. Thanks in advance.

Bro can you help me with this problem. I am having the same having an issue with the purchase event. Do we need to set up custom data inside the purchase tag as per coding? or data layer?