Francesca
Francesca

Reputation: 28128

Using universal analytics to track click events

I currently have the following to initialise Google Analytics on my site:

<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-123456-1', 'auto');
          ga('send', 'pageview');
        </script>

I have added the following to all links on my page:

onclick="ga('send', 'event', 'Link', 'Example');"

What callback do I need to add to my GA script in order for this to work correctly?

Upvotes: 0

Views: 44

Answers (1)

nyuen
nyuen

Reputation: 8907

Looks good. You can check in Real-Time reports to see immediately if the event is tracking (assuming you are not filtering out your own visits). Make sure the all onclick code comes after the GA snippet. You can also consider using GTM to tag all your links if they are all different, in case you have more links to add in the future.

Upvotes: 1

Related Questions