GTM data layer eventCallback function

后端 未结 4 553
猫巷女王i
猫巷女王i 2021-01-07 01:59

So i have Ecommerce code setup in GTM data layer, but after that is sent to Analytics i want the page to be redirected so i know i should be using eventCallback but it is no

相关标签:
4条回答
  • 2021-01-07 02:06

    i think i found a solution, i just added this ('event' : 'datalayerReady') at the end of the data layer:

    'event' : 'datalayerReady',
    'eventCallback': function() {
      document.location = "https://www.paypal.com/something";
    }
    
    0 讨论(0)
  • 2021-01-07 02:07

    Dreadlord,

    try using this: (no href after window.location)

    'eventCallback': function() {
        window.location.href = 'https://www.paypal.com/something';
    }
    

    This should fix it. Hope this helps, Petr

    0 讨论(0)
  • 2021-01-07 02:16

    This works well for me.

    <script type="text/javascript">
    if (typeof dataLayer !== "undefined") {
            dataLayer.push({
                'event': 'MyEvent',
                'eventCallback' : function() {
                    window.location = 'http://stackoverflow.com/questions/26802554/gtm-data-layer-eventcallback-function';
                }
            });
        }
    </script>
    <noscript>
        <meta http-equiv="refresh" content="0;url=http://stackoverflow.com/questions/26802554/gtm-data-layer-eventcallback-function" />
    </noscript>
    
    0 讨论(0)
  • 2021-01-07 02:29

    Taken from: http://www.simoahava.com/gtm-tips/use-eventtimeout-eventcallback/

    Always add the eventTimeout parameter when using eventCallback. The former takes a numerical value as its parameter, representing the number of milliseconds to wait before calling eventCallback anyway. In other words, even if your Tags stall and never signal completion, after two seconds eventCallback is invoked.

    window.dataLayer.push({
      'event' : 'processLink',
      'eventCallback' : function() {
        window.location = targetUrl
      },
      'eventTimeout' : 2000
    });
    
    0 讨论(0)
提交回复
热议问题