Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

[🐞]: forwarding gtm dataLayer.push breaks immediate dataLayer pushes #596

Open
DzmVasileusky opened this issue May 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@DzmVasileusky
Copy link
Contributor

DzmVasileusky commented May 22, 2024

Describe the bug

Partytown and GTM integration docs page says we should add dataLayer.push to the forward array.
But after doing it immediate call of dataLayer.push stops to work.

index.html

        <script src="/head-scripts/partytown.config.js"></script>
        <script src="/~partytown/debug/partytown.js"></script>
        <script>
            if (!navigator.isServer) {
                (function (w, d, s, l, i) {
                    w[l] = w[l] || [];
                    w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
                    var f = d.getElementsByTagName(s)[0],
                        j = d.createElement(s),
                        dl = l !== 'dataLayer' ? '&l=' + l : '';
                    j.type = 'text/javascript';
                    j.async = true;
                    j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
                    f.parentNode.insertBefore(j, f);
                })(window, document, 'script', 'dataLayer', '#gtmAccountId#');

                // Immediate call of dataLayer.push which is working if not forwarded
                window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                    partyTownEnabled: true,
                    event: 'Partytown_ready'
                });
            }
        </script>

/head-scripts/partytown.config.js

partytown = (function () {
    const FORWARD_LIST = [
        'dataLayer.push'
    ];
    return {
        forward: FORWARD_LIST
    };
})();

If I am removing it from forwarded list - it works like a charm.

Reproduction

https://tp8h37-5000.csb.app/

Steps to reproduce

  1. Open the reproduction url.
  2. Disabled Adblock, Ublock and other gtm blocking extensions
  3. Open the console

Actual:
Only GTM started message is output

Expected:
GTM started and
Partytown enabled: true messages are output

Browser Info

Chrome

Additional Information

Not sure but maybe it is caused by this partytown code delete win[property.split(".")[0]];

@DzmVasileusky DzmVasileusky added the bug Something isn't working label May 22, 2024
@DzmVasileusky
Copy link
Contributor Author

Actually adding defer to both partytown config and script solved the issue. But not sure if it is a good idea to defer partytown

@thekingbk90
Copy link

Although dataLayer.push isn't working in chrom console, most of data is pushed to gtag manager.
However we missed all data from mobile web, maybe partytown works only on desktop version?

@DzmVasileusky
Copy link
Contributor Author

@thekingbk90 Not sure what case are you describing but it definitely doesn't send an event in my example.
I set up a testing project in gtm and tag was never triggered.

Setting 1000ms timeout or excluding it from forward makes it work. But my intention is to pass a feature flag to manage which gtm scripts should be handled by partytown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants