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.98k stars 428 forks source link

[Help] I can't make Party Town work #86

Closed federicogfernandez closed 2 years ago

federicogfernandez commented 2 years ago

Hey, i need some help to setup Party Town

I'm building a Remix application and i added the library with the React component you provide <Partytown debug={true} forward={['dataLayer.push']} /> The following script is being added to the head

!(function(w,p,f,c){c=w[p]=Object.assign(w[p]||{},{"debug":true});c[f]=(c[f]||[]).concat(["dataLayer.push"])})(window,'partytown','forward');/* Partytown 0.3.6 - MIT builder.io */
!function(t,e,n,i,r,o,a,d,s,c,p,l){function u(){l||(l=1,"/"==(a=(o.lib||"/~partytown/")+(o.debug?"debug/":""))[0]&&(s=e.querySelectorAll('script[type="text/partytown"]'),i!=t?i.dispatchEvent(new CustomEvent("pt1",{detail:t})):s.length&&(d=setTimeout(f,1e4),e.addEventListener("pt0",g),r?h(1):n.serviceWorker?n.serviceWorker.register(a+"partytown-sw.js",{scope:a}).then((function(t){t.active?h():t.installing&&t.installing.addEventListener("statechange",(function(t){"activated"==t.target.state&&h()}))}),console.error):f())))}function h(t){c=e.createElement(t?"script":"iframe"),t||(c.setAttribute("style","display:block;width:0;height:0;border:0;visibility:hidden"),c.setAttribute("aria-hidden",!0)),c.src=a+"partytown-"+(t?"atomics.js":"sandbox-sw.html?"+Date.now()),e.body.appendChild(c)}function f(t,n){for(g(),t=0;t<s.length;t++)(n=e.createElement("script")).innerHTML=s[t].innerHTML,e.head.appendChild(n);c&&c.parentNode.removeChild(c)}function g(){clearTimeout(d)}o=t.partytown||{},i==t&&(o.forward||[]).map((function(e){p=t,e.split(".").map((function(e,n,i){p=p[i[n]]=n+1<i.length?"push"==i[n+1]?[]:p[i[n]]||{}:function(){(t._ptf=t._ptf||[]).push(i,arguments)}}))})),"complete"==e.readyState?u():(t.addEventListener("DOMContentLoaded",u),t.addEventListener("load",u))}(window,document,navigator,top,top.crossOriginIsolated);document.currentScript.dataset.partytown="";

I have also added GTM script following the docs.

But it looks like nothing happens, it doesn't log anything to the console, it doesn't load the service worker.

Am i missing something?

Legym commented 2 years ago

Did you do something like this?

        <Partytown
          debug={ true }
          forward={['dataLayer.push']}
        />

                <script type="text/javascript" dangerouslySetInnerHTML={ {
          __html: `
// 3rd party code here
          `
        } } />

and im not familiar with remix, but did you place this into the head?

federicogfernandez commented 2 years ago

Hey, thanks for the response. It was my fault, i was trying to load the script on http and SW doesn't work with http. Now i have PartyTown running and i can test my analytics integration.