Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experience with Partytown and Server Side Tagging? #501

Closed
j0Shi82 opened this issue Nov 20, 2023 · 1 comment
Closed

Experience with Partytown and Server Side Tagging? #501

j0Shi82 opened this issue Nov 20, 2023 · 1 comment

Comments

@j0Shi82
Copy link
Contributor

j0Shi82 commented Nov 20, 2023

Hey folks!

We recently adopted Partytown for a Shopify OS 2.0 shop and ran into some trouble integrating Partytown with our Tagging Server. One thing I quickly realized was that tracking cookies weren't set at all in the shop. document.cookie works fine, but cookies from the server get set by HTTP headers, which doesn't seem to work.

I did a little testing and apparently the issue is using XMLHttpRequest inside Web Workers, even if the withCredentials property is properly set. I could reproduce that cookies are neither send to, nor set by the server using XMLHttpRequest.withCredentials (which Google Analytics does for example).

The fetch-API doesn't have the same issue as long as the credentials-setting is included. I set up a small test site (it's a personal test site without proper consent management, so be warned) that checks on cookies using different Tagging-Methods. You can click the links at the top of the page to go through scenarios:

  • SGTM (Server Side Tagging)
  • SGTM & PT (Server Side Tagging inside Partytown)
  • GTM (Client Side Tagging)
  • GTM & PT (Client Side Tagging inside Partytown)

I also included a TEST-COOKIE that gets set from a fetch-Request inside Partytown if you're using Server Side Tagging. You'll notice that all client cookies get properly set when using Client Side Tagging with or without Partytown. Server Side Tagging also works just fine without Partytown, but adding Partytown to the mix only sets the TEST-COOKIE from fetch but fails to set all the others from XMLHttpRequest.

Has anyone tested an implementation of Partytown and Server Side Tagging and is able to provide some insight?

@j0Shi82
Copy link
Contributor Author

j0Shi82 commented Jan 28, 2024

I've updated the test site with another option that shows a potential fix: https://www.partydawn.top/?sgtm&pt&xhrfetch

For all scripts that use XMLHttpRequest, I added a new class that implements the original API but uses fetch under the hood. It seems to work. I branched off of https://github.com/apple502j/xhr-shim/blob/main/src/index.js and serve the shim directly from a Cloudflare URL Proxy.

I'm currently trying to set up a test that shows the issue and a potential PR that includes the shim directly in Partytown. It's probably a niche issue, but being able to run Partytown with a Tagging Server (or anything that tries to Set-Cookie from HTTP headers) would be a nice benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant