Skip to content

Instantly share code, notes, and snippets.

@pazguille
Last active April 9, 2024 18:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pazguille/fed1899cf1810c8818dcf3694f59ee3e to your computer and use it in GitHub Desktop.
Save pazguille/fed1899cf1810c8818dcf3694f59ee3e to your computer and use it in GitHub Desktop.
Use Partytown πŸŽ‰ without frameworks
<!doctype html>
<html lang="es-AR">
<head>
<meta charset="utf-8" />
<meta name="HandheldFriendly" content="True" />
<link rel="preconnect" href="https://www.dolarsi.com" />
</head>
<body>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXX', {
storage: 'none',
anonymize_ip: true,
allow_google_signals: false,
allow_ad_personalization_signals: false,
});
var s = document.createElement('script');
s.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXX';
s.async = 1;
s.type='text/partytown';
var m = document.getElementsByTagName('script')[0];
m.parentNode.insertBefore(s,m);
</script>
<script>
window.addEventListener('load', function() {
requestIdleCallback(() => {
/** https://partytown.builder.io/forwarding-events
Configurar el forward para GTM
*/
window.partytown = { forward: ['dataLayer.push'] };
/** https://partytown.builder.io/copy-library-files
1. Instalar con NPM @builder.io/partytown
2. Ejecutar: partytown copylib ~partytown (con un npm-script)
3. Copiar el contenido del archivo ~partytown/partytown.js
*/
!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})):(d=setTimeout(w,1e4),e.addEventListener("pt0",f),r?h(1):n.serviceWorker?n.serviceWorker.register(a+(o.swPath||"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):w())))}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?v=0.5.4":"sandbox-sw.html?"+Date.now()),e.body.appendChild(c)}function w(t,n){for(f(),t=0;t<s.length;t++)(n=e.createElement("script")).innerHTML=s[t].innerHTML,e.head.appendChild(n);c&&c.parentNode.removeChild(c)}function f(){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,window.crossOriginIsolated);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment