So reading in the guides I see that in order to track the ID you need this:
_paq.push(['setUserId', 'USER_ID_HERE']);
Then we have the full example:
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
_paq.push(['setUserId', 'USER_ID_HERE']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//{$MATOMO_URL}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', {$IDSITE}]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
Now in the example above it shows that I need to call the user ID before I call pageview, here’s my question:
I’m going to use user’s email as the ID, and I’m going to get that email when a significant event happens such as lead, book a call or purchase.
Now lead, book a call or purchase doesn’t happen on page load, people need to take actions for that to happen. Exception here can be purchase but I’m not using page load as a way to trigger purchase events instead I hook into events and wait for the user to buy and spend money and then I trigger the purchase event.
My question is, if I call this code:
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//{$MATOMO_URL}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', {$IDSITE}]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
which doesnt’ have: _paq.push([‘setUserId’, ‘USER_ID_HERE’]); before the page view, and I wait for the lead, book a call or purchase event, can I then simply just call this:
_paq.push([‘setUserId’, ‘USER_ID_HERE’]);
will that work?
or is calling the push for user ID tied to the whole code below:
<script type="text/javascript">
var _paq = window._paq = window._paq || [];
_paq.push(['setUserId', 'USER_ID_HERE']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//{$MATOMO_URL}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', {$IDSITE}]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
Meaning the code for pushing the user ID will not work without the whole code above…
Can anyone shine some light for this situation please…