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

docs: Copy window example from SvelteKit implementation docs #578

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading