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: revert recent docs changes making gtag a window global #623

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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: 0 additions & 12 deletions docs/forwarding-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ 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 || [];
window.gtag = function gtag(){dataLayer.push(arguments);}
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'YOUR-ID-HERE');
Expand Down
10 changes: 3 additions & 7 deletions docs/sveltekit.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ Adapting from [the HTML integration guide](https://partytown.qwik.dev/html)

## 3. Then add 3rd party scripts

This is where we use partytown to add those scripts (note `type="text/partytown"` below). 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 Google Tag Manager. Note `window.gtag = function()` instead of `function gtag()`.

Putting it together with the previous changes, our `+layout.svelte` looks like:
This is where we use partytown to add those scripts (note `type="text/partytown"` below). This example shows Google Tag Manager. Putting it together with the previous changes, our `+layout.svelte` looks like:

```svelte
// src/routes/+layout.svelte
Expand All @@ -67,7 +63,7 @@ Putting it together with the previous changes, our `+layout.svelte` looks like:
<script>
// Forward the necessary functions to the web worker layer
partytown = {
forward: ['dataLayer.push', 'gtag']
forward: ['dataLayer.push']
};
</script>

Expand All @@ -76,7 +72,7 @@ Putting it together with the previous changes, our `+layout.svelte` looks like:
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=YOUR-ID-HERE"></script>
<script type="text/partytown">
window.dataLayer = window.dataLayer || [];
window.gtag = function(){dataLayer.push(arguments);}
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR-ID-HERE');
</script>
Expand Down
Loading