0
votes

In our website, we need to send an event with an event value on some pages when the page is loaded.

When we've added the following code to the bottom of our page (after the google analytics script) we don't receive any event record on Google analytics reports.

<script>
    ga('send', 'event', 'Showed a page', 'Showed a page', 'Page Type', 12);
</script>

where the 12 is an example event value.

We get the events triggered when they're connected to onClick event of something but couldn't find the optimised way of doing it on page load.

1
As long as your tracker has been created before, and uses the default name (which it will, unless you have specifically set a tracker name) this should work. So there must be some other issue which prevent the call from firing (e.g. you might have placed to tracker creation inside a jquery document.ready call, or there is some global javascript error). The browser developers tools are the thing to check now (or if you can give an url we can have a look). - Eike Pierstorff

1 Answers

0
votes

First I believe you should place your analytics.js tracking snippet as high in the as possible(not before tags ofc) as per the instructions here. One issue is that your command is never put inside the ga() command queue. One thing you can do is put your required function after the pageview command that I believe you already get correctly in your Analytics Interface. Also are there any errors being logged in your web browsers console?Also you can try and send your event when the analytics.js library has fully loaded. A discussed implementation can be found here.