Coder Social home page Coder Social logo

stape-io / facebook-tag Goto Github PK

View Code? Open in Web Editor NEW
37.0 12.0 20.0 305 KB

Facebook tag for Google Tag Manager Server Side

Home Page: https://stape.io/how-to-set-up-facebook-conversion-api/

License: Apache License 2.0

Smarty 76.98% JavaScript 23.02%
facebook-tag facebook-conversion-api gtm gtm-server-side gtm-custom-template facebook stape analytics

facebook-tag's People

Contributors

bukashk0zzz avatar dmtsolovey avatar freestream avatar giovaniortolani avatar khorozhanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facebook-tag's Issues

Template review feedback

Thanks for submitting a template to the gallery, there were a few issues in your template that needed to be resolved ahead of approving the template for the gallery.

  1. We see console errors while doing "run code". Can you please resolve the issue.
    Screenshot 2021-03-31 11 56 29 AM

Duplicate Purchase event issue

I am sending through GTM a purchase event using the GA4 client, the event is being received as a single purchase event, but is generating 2 events in Facebook, I have 2 ad accounts but can see the separate requests, but I also see on the console the raw and mapped data, not sure what to do there is only one event on the client, and one event coming into the GTM server but 2 pixel events in Facebook. There is no other code generating a pixel purchase event

[Feedback] Using stable JS formater

Hi team,

So thank you to create useful tag, your work is so delight!

Btw, I have a feedback, that could you use a stable JS formater so the code diff in every release is easy to read and audit. :)

image

Thanks,

P/s : this is not a problem issue but just a feedback, I will close after 7 days or you can close. ๐Ÿ˜„

fbp & fbc cookies should be generated

I saw in issue #2 that this was closed, but I believe these cookies should be set. Instead, I get a FPID, FPID2, and FPLC cookie and when making a request to Facebook it looks for "very_important_cookies" which are fbp and fbc... which would obviously be null since this template doesn't set those values.

Invalid Input in Template Preview Error

When importing the template.tpl file into Tag Templates, I'm getting an "Invalid input in Template Preview" error and then I can't use the template when creating a tag. Was trying to debug but the error isn't very helpful. Please see the screenshot:
Screen Shot 2021-04-23 at 9 19 46 PM

Server Side - Facebook Parameters Invalid

Hi,
Thanks for your valuable input on Facebook Conversion API. In the course of our implementation we have faced some issues. We haved used inherit method to send events to server containers facebook tag.
First of all the pageview and impression tags we have on the web container for view item, add to cart, checkout and purchase are not working as server side tags. Some parameters have errors. Could you help us with this? Is there something we are doing wrong?
Secondly although we have currency and value sent as facebook parameters, we are getting errors? Could you explain us, which steps we need to follow here?
Thank you for your support.
Best regards,
You can find the errors we are reciveing in the screenshots attached.

serverside-console
view_item-400
gtmserverside

Ecommerce data: change content-type

Hi there!

Thanks for this great library! I was wondering if I can change the content_type for the e-commerce data in this tag. I need to set it to 'product_group' and not 'product'. I see that I can change this in the code, however it is maybe better to create some extra setting for this. With an update, this code would be removed.

Kind regards,

Bas

eventData._fbc & eventData._fbp

Hi,

is this code wrong ?

if (!fbc) fbc = eventData._fbc;
if (!fbp) fbp = eventData._fbp;

In fact it is not possible to set fields with a name starting with an underscore in the tag GA4 of the GTM Web

Best regards

Compatibility with gtm4wp Product ID prefix

This is a tricky one so hopefully I explain it correctly :)

gtm4wp (our main data layer source for a WP/Woo store) has a Product ID prefix field

which is very useful to ensure gtm4wp is compatible with WooCommerce product feeds plugins like Google Product Feed which adds the woocommerce_gpf_ to all products in the feeds it produces.

the gtm4wp data layer for GA4 eCommerce events then includes this prefix in the items.id key while preserving the original product id in the items.item_id key

This presents a problem for me as your facebook capi tag will use item_id rather than the id key

      if (d.item_id) content.id = d.item_id;

Rather than setting up my own custom vars/events, I was able to easily solve this by simply replacing the line above with
if (d.id) content.id = d.id;

which ensures the prefixed version gets sent on to the server side.

I'd rather not have to maintain my own fork of your excellent tag :) So I'm wondering if there's some way to add an option to set which key a user would prefer to use (e.g. id vs. item_id) which would ensure no breaking changes for your other customers but also improve compatibility with most common WooCommerce extensions that produce feeds with prefixes?

Thanks.

content_ids missing?

Hi there,
I just came across an issue in our integration using the tag manager server container. It seems like your tag is not setting the "content_ids", but just the "contents" array when interacting with a product in our shop. Are we missing a parameter in our GA4 integration?
Screenshot 2021-12-04 at 14 25 09

Seems like the content_ids needs to be an array of all product_ids that are already in the contents array.. I don't know, why Facebook needs this information twice, but I can see for example in the Facebook commerce manager, that it can't match any event from our page with our product data feed, because it seems to use just the content_ids array for that.

httpOnly option doesn't set cookie as HttpOnly

Action
Change the boolean value of httpOnly to true for the cookies _fbc and _fbp

Expected Result
The cookie is set with the HttpOnly flag in the response to the browser.

Actual Result
The cookie is not set with the HttpOnly flag in the response to the browser.

Cause
In the template code, httpOnly is camelCase. Changing this to PascalCase (i.e. HttpOnly: true) sets the cookies with the correct HttpOnly flag.

Context
We're trying to remove all Facebook Javascript from our websites. After the implementation of the option to set the _fbp cookie (thanks!), the last step was to have all cookies be readable only by our SSGTM container. The goal is make what we're reporting to Facebook more accurate, especially in browsers with strict privacy restrictions (by removing the browser from the equation as much as we can).

I tested the above cause and fix with Simo Ahava's Cookie Monster tag template. That change in case was the only difference present. After making the change in stape-io/facebook-tag and retesting without Cookie Monster (and with clearing cookies), the _fbc and _fbp cookies were properly set as HttpOnly. This is because the camelCase option names are only valid options for Google's setCookie() function - httpOnly is not a valid option of that function. However HttpOnly (PascalCase) is a default param of how setCookie() is actually setting the cookie in the response - not the function, itself. This bypasses the lack of httpOnly option in the sandboxed setCookie() function.

Recommend adding a checkbox/boolean flag for setting cookies via HttpOnly with this method.

Resources
setCookie() API reference
Cookie Monster Tag Template by Simo Ahava

fbp&fbc should be set by us?

Hi there,

What do we need to change/configure in order to use remarketing? Do we need at least to autogenerate fbp (or get from cookie if exists), the same linke fbc? Should we modify tag code?

If new user fbp value differs if batched events

I use GTAG client side to send events to sGTM. If two events are sent almost at the same time or are being batched - e.g. page_view and view_item - and the visitor is new so there is no fbp cookie set, the result is a different fbp in the first and the second hit to the Conversion API.
I have enabled 'Generate _fbp cookie if it not exist' and 'Use HttpOnly cookies'. I guess this issue is a result of the fact that the first tag doesn't make it to set the cookie before the next event is triggered.
The 'Google Analytics: GA4' client seems to be able to handle this - probably because it is the client that sets the cookie instead of the tag.
A solution could be to generate the fbc value client-side and then send it along on every request. Then in the code check if there is a cookie value set - if not use the fbc value generated client-side and set that as the value of the _fbc cookie.

Facebook Event Manager can't display server event without test code

When I set a test code in the tag, the event manager can actually display that a server event is received. However, when I publish the container without test code, the event manager stop showing any server events. I verified that in preview mode the graph api returned 200.

Moreover, if I used another tag from facebook incubator, I am able to view server side event counts are increasing. Looking at their source code, I noticed that they used a lower api version (the one published in server side gtm gallery is v12.0) and different partner agent (gtmss-1.0.0-0.0.5). So I was wondering if I didn't use this tag properly or it has anything to do with api version or partner agent?

Publish Issue

Hello,
When I tried to publish, I got this issue

Internal error Unknown Unknown vendor template key: public_id: "cvt_45869499_4"

facebook tag not fully compatible with Stape Data tag

Your server side fb tag expects a lastName key

if (eventData.lastName) mappedData.user_data.ln = eventData.lastName;

The Stape Data Tag sends over the following event data array (note: the key in the user_data event is last_name not lastName

which means only city and email are currently picked up automatically

"user_data":{"client_user_agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1","client_ip_address":"188.141.52.86","external_id":"7a2c5f44c553096c00bd05e62c4f3771","em":"81fc968a7802dc094911964c838e21694a37f4a6d0eb8765b8df92004cf36994","ct":"be7a545f8fee1cb7a51e371778e8ac06ef1ec22c0c5e75fa3e8710464ca84821"},"event_id":"1671450251938_16715344109898"}],"partner_agent":"stape-gtmss-2.0.0"}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.