We are using a server-side tag setup for GTM where the data is passed to the server as a GA4 Purchase event and then sent along to FB CAPI using this Facebook Incubator tag template.
I've written a custom Javascript variable in GTM to parse a Google Analytics ecommerce "products" array and return it in the format FB CAPI wants for "contents":
As you can see, it takes the price, quantity, and sku for each item and saves them in the correct format. I am explicitly passing this array as "contents":
However, trying to pass the purchase events to the server is failing with code 400 and receives the following response:
"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":2804008,"is_transient":false,"error_user_title":"Invalid Contents Parameter","error_user_msg":"The contents parameter you entered doesn\u2019t contain a list of JSON objects. Enter a list of JSON objects that contain the product IDs associated with the event plus information about the products. For example: [{ 'id' : 'ABC123', 'quantity' : '2', 'item_price' : 5.99}, { 'id' : 'XYZ789' , 'quantity' : 2, 'item_price' : 9.99}]","fbtrace_id":"ASsXl7dWNIzLxh8RdCpOp45"}}
Digging in, it seems like the tag is somehow creating its own "content" array and ignoring the one I'm sending. In the process, it seems to be grabbing the wrong field, using "name" instead of "sku". This is the request body it is sending (some data anonymized):
{"data":[{"event_name":"Purchase","event_time":1656000012,"event_source_url":"https://www.customer.com/order/checkout","action_source":"website","user_data":{"client_ip_address":"111.111.111.111","client_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36","ph":"a1b2c3d4e5f6...abcdef","fbp":"fb.1.1111...1111"},"custom_data":{"currency":"USD","value":7.94,"order_id":"4f719af2-3637-42ee-8e8a-28e8f3783858","contents":[{"title":"Homestyle Huddle Wrap","item_price":7.49,"quantity":1}]}}],"partner_agent":"gtmss-1.0.0-0.0.5"}
Specifically, note the contents array:
"contents" : [
{
"title" : "Homestyle Huddle Wrap",
"item_price" : 7.49,
"quantity" : 1
}
]
This is not what's being passed, and it actually doesn't match any of our objects- we don't use "title" anywhere in our objects, so this object in this format has to be coming from this tag template.
However, that seems to be making it fail, since FB is expecting "id" but getting "title"? In other words, FB's tag seems to be ignoring the provided "contents" array and instead building its own, but FB CAPI seems to be rejecting the "contents" array built by FB's own tag.
Any thoughts on why this is happening and how to fix it? Why isn't the tag using the "contents" array I have already built and am sending to it, and why is the one it appears to be building failing?