stape-io / facebook-tag

Facebook tag for Google Tag Manager Server Side
https://stape.io/how-to-set-up-facebook-conversion-api/
Apache License 2.0
37 stars 21 forks source link

If new user fbp value differs if batched events #17

Closed sorendam closed 2 years ago

sorendam commented 2 years ago

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.

Bukashk0zzz commented 2 years ago

Hi,

Thanks for this report. I added check for _fbc web cookie. And if it correct new one not will be generated. https://github.com/stape-io/facebook-tag/blob/main/template.js#L42