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

[Feature request] Add support for Partytown #518

Open
digitalcortex opened this issue Jan 24, 2023 · 2 comments
Open

[Feature request] Add support for Partytown #518

digitalcortex opened this issue Jan 24, 2023 · 2 comments

Comments

@digitalcortex
Copy link

Page speed insights is complaining about Google Analytics module blocking the main thread. I figured that Partytown web worker can help avoid blocking the main thread when using analytics.

Is there any chance it could be supported out of the box?

@angelov-a
Copy link

+1

Adding support for Partytown is fairly straightforward.

It's a matter of setting a special type for the gtag script and notifying Partytown.

export const load = (url, options = {}) => {
  return new Promise((resolve, reject) => {
    if (typeof document === "undefined") {
      return;
    }

    const head = document.head || document.getElementsByTagName("head")[0];
    const script = document.createElement("script");

    /* ... */

    if (options.partytown) {
      script.type = 'text/partytown'; // mark the script for partytown
    }

    head.appendChild(script);

     if (options.partytown) {
      window.dispatchEvent(new CustomEvent('ptupdate')); // trigger partytown rescan
    }

    /* ... */
  });
};

@kurwaBober
Copy link

need this feature so much

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

3 participants