Skip to content

Commit

Permalink
docs: Copy window example from SvelteKit implementation docs (QwikDev…
Browse files Browse the repository at this point in the history
  • Loading branch information
cornedor authored Apr 10, 2024
1 parent 075aafa commit 710ea8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions docs/forwarding-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ However, since GTM and Facebook Pixel were actually loaded in the web worker, th

Notice the forward configs are just strings, not actual objects. We're using strings here so we can easily serialize what service variable was called, along with the function argument values. When the web worker receives the information, it then knows how to correctly apply the call and arguments that were fired from the main thread.

If your script declares global functions or variables, make sure they are explicitly declared with `window` and forwarded to the web worker. This example shows the gtag function from Google Tag Manager. Note `window.gtag = function gtag()` instead of `function gtag()`.

```html
<script>
window.dataLayer = window.dataLayer || [];
window.gtag = function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR-ID-HERE');
</script>
```

You can customize each forwarded variable with the following settings:

- ### preserveBehavior
Expand Down
2 changes: 1 addition & 1 deletion docs/google-tag-manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Set the script element's `type` attribute to `text/partytown`. For example:
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
window.gtag = function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR-ID-HERE');
Expand Down

0 comments on commit 710ea8d

Please sign in to comment.