If you want to send multiple events at once on one page view, it’s better to combine them than to fire them one-by-one after each other.
Start by splitting up the basic script into two pieces:
1.
<script type="text/javascript">
var _paq = _paq || [];
</script>
2.
<script type="text/javascript">
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://tr.datatrics.com/";
_paq.push(["setTrackerUrl", u]);
_paq.push(["setProjectId", "PROJECTID"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
g.type="text/javascript";
g.defer=true; g.async=true; g.src=u; s.parentNode.insertBefore(g,s);
})();
</script>
The first (1) piece should be loaded first. After that, add the other scripts you want to send over after this (like product views and shopping cart updates), but remove the _paq.push(["trackPageView"]); lines. After the extra events, fire the second piece (2) of the tracking script above.
Example of firing multiple events at once
In the example below, we will load the tracking script, but also track a product view, a shopping cart and a custom conversion:
<script type="text/javascript">
// Setting the _paq variable
var _paq = _paq || [];
// Tracking a product view
_paq.push(['setEcommerceView',
"9780786706211",
"Endurance: Shackleton's Incredible Voyage",
"Adventure Books",
20.11
]);
// Track the shopping cart
_paq.push(['addEcommerceItem',
"7659837658343",
"Nike Shoe",
"Shoes",
70,
1
]);
_paq.push(['trackEcommerceCartUpdate',
70
]);
// Track a custom conversion
_paq.push(['trackGoal', 3]);
// Sending all data to our servers
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://tr.datatrics.com/";
_paq.push(["setTrackerUrl", u]);
_paq.push(["setProjectId", "PROJECTID"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0];
g.type="text/javascript";
g.defer=true; g.async=true; g.src=u; s.parentNode.insertBefore(g,s);
})();
</script>