javascript - Can I split Google analytics require/send into separate script tag -


can this?

put in head:

      <script>       (function(i,s,o,g,r,a,m){i['googleanalyticsobject']=r;i[r]=i[r]||function(){       (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new date();a=s.createelement(o),       m=s.getelementsbytagname(o)[0];a.async=1;a.src=g;m.parentnode.insertbefore(a,m)       })(window,document,'script','//www.google-analytics.com/analytics.js','ga');        ga('create', 'ua-xxxxxxxx-1', 'auto');       ga('send', 'pageview');        </script> 

and this, somewhere in body on part of same page?

<script> ga('require', 'ecommerce');  ///transaction info  ga('ecommerce:send'); </script> 

or ecommerce require/send both have in 1 script in head.

thanks!

it should work ecommerce code below main tracking code (you can test out running code in console after page has loaded, , checking if transaction hit sent). note if page doesn't load reason, , have ecommerce code @ bottom, there may chance that code doesn't run, , lose ecomm tracking.


Comments