BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
12.85k stars 426 forks source link

Is it possible to use partytown to third party scripts like glaze, dynatrace, etc? #302

Open ghost opened 1 year ago

ghost commented 1 year ago

Is your feature request related to a problem? Please describe. We use multiple third-party analytics in our svelte application. We integrated partytown in our svelte app for executing those analytics scripts and calls through partytown but we were able to achieve it only for Google Tag Manager, we need to know if the same is possible for others.

Describe the solution you'd like Just like the forward configs used for services like Google tag manager and facebook pixel, can we have any config feature/documentation for services like glaze, dynatrace, medallia, etc. if it is possible to trigger those respective calls through partytown.

Describe alternatives you've considered We used text/partytown as type for downloding glaze script but only script execution is handled by partytown and the corresponding log calls are not triggered. Without out partytown if we run the script in main thread, the respective log calls are triggered as expected.

mhevery commented 1 year ago

In theory, this should work, but if it does not, we need steps to reproduce it. Can we have an HTML file showing how you have it set up and what steps we need to take to reproduce the problem? Without that, it is not possible to know what is going on and what needs to be fixed.

ghost commented 1 year ago

In theory, this should work, but if it does not, we need steps to reproduce it. Can we have an HTML file showing how you have it set up and what steps we need to take to reproduce the problem? Without that, it is not possible to know what is going on and what needs to be fixed.

Hi Mr.Hevery, I have created a sample application for reproducing dynatrace issue. link: https://codesandbox.io/s/github/vasikaranb-nagarro/partytown_poc/tree/dynatrace

there, in index.html , if you change the script type as text/javascript in the dynatrace script you can see log calls getting triggered for url change. But the same is not happening with type partytown. <script type="text/partytown" src="https://js-cdn.dynatrace.com/jstag/147f84b2bdc/bf45848ori/3cd9a81926e1a501_complete.js">

Github link : https://github.com/vasikaranb-nagarro/partytown_poc/tree/dynatrace To reproduce locally, Please clone the repo (branch: dynatrace) and do npm dev

ghost commented 1 year ago

For Glaze.ai, the issue with partytown is, glaze fetches changes from window.location.href to make log calls. and it works fine with partytown nomally, but if we have base URL for the application, then it fails because partytown doesnt update its self.location.href if we have base href.

Steps to reproduce:

  1. clone https://github.com/vasikaranb-nagarro/partytown_poc/tree/glaze
  2. npm install and npm dev
  3. glaze logs will be triggered if we remove base href from index.html and config(base url) from app.svelte

Solution needed: Can self.location object in partytown webworker be updated with url change even if we have base href

mhevery commented 1 year ago

I will try to look into it later this week.

mhevery commented 1 year ago

I tried to debug it, but I really have no idea what I am looking for or how to reproduce it. Can you provide a more steps by steps instructions os to what to click and what to look for? https://www.loom.com/share/5f155e209111469cb89c3b97aa8f265b

ghost commented 1 year ago

I tried to debug it, but I really have no idea what I am looking for or how to reproduce it. Can you provide a more steps by steps instructions os to what to click and what to look for? https://www.loom.com/share/5f155e209111469cb89c3b97aa8f265b

Hi Misko,

I am adding the steps to reproduce the issue.

Dynatrace

  1. Please take a pull from https://github.com/vasikaranb-nagarro/partytown_poc/tree/dynatrace as dynatrace URL has been updated now.
  2. npm install and npm dev
  3. in index.html file you can see the dynatrace script tagged under javacsript type image
  4. In the browser -> inspect -> network tab, you can see dynatrace XHR calls getting triggered in every URL change (click tweets button in home page and back button in tweets page) image
  5. Now change the dynatrace script type to partytown in same index.html file. We don't see those calls getting triggered

Analysis : dynatrace uses window object to push data and trigger calls. image Since webworkers doesnt have window object or its access, this scenario is failing. For GTM, partytown has a config called 'forward' which forwards the respective data to window.dataLayer object. Can we have similar config for dynatrace?

Glaze

  1. Please take a pull from https://github.com/vasikaranb-nagarro/partytown_poc/tree/glaze
  2. npm install and npm dev
  3. In index.html we have glaze script with javascript type. image
  4. In the browser->inspect->network tab, we can see glaze log calls in every URL change. ( Click tweets button in home page and back button in tweets page) image
  5. Now, if we change the glaze script to partytown type, those calls will not be triggered.

Analysis: This glaze issue is happening only when we have base href in the application image With some debugging I found that partytown has location object on its own (self.location). and this location.href is not getting updated with URL change if we have base href. most probably the issue is with the set href() methods in partytown-atomics.js files.

ghost commented 1 year ago

Hi Misko, were you able to reproduce the issue with above steps? Please let me know if any more information is needed.

FYI, By mistake closed this issue but re-opened it immediately.

mhevery commented 1 year ago

I am sorry, I got buried with other things. Still on my list.

mhevery commented 1 year ago

https://github.com/BuilderIO/partytown/pull/331

mhevery commented 1 year ago

Still more work to do here...

ghost commented 1 year ago

Hi Misko, Hope you are doing good. please let me know if the recent version has any fix related to this issue.

mhevery commented 1 year ago

Hey, I am currently traveling but should have time to look at this next week.

On Thu, Jan 12, 2023 at 9:14 AM Vasikaran B @.***> wrote:

Hi Misko, Hope you are doing good. please let me know if the recent version has any fix related to this issue.

— Reply to this email directly, view it on GitHub https://github.com/BuilderIO/partytown/issues/302#issuecomment-1379824374, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA3KT7KHGTUVNXVHTYQZYLWR6HJRANCNFSM6AAAAAASCJSUEY . You are receiving this because you modified the open/close state.Message ID: @.***>

sushil-netspend commented 1 year ago

Hi Misko, is there any update on this, did you get a chance to look at it?

mhevery commented 1 year ago

Sorry, our focus currently is on Qwik. We would need someone to debug this further.