Solved

javascript custom events tracking code

Posted on 2015-02-24
2
82 Views
Last Modified: 2015-08-20
hey everybody I need some help with tuning GA events tracking code. I need to track OutboundLink clicks and pass data to GA. It is a directory page of books and I need to pass book category as Event Cat, book publisher as Event Action and link as Event label. How can I get this information to pass it to GA?
0
Comment
Question by:webdirexion
  • 2
2 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 40763582
I'm using GA Universal and track all of my outbond links using this function:
var trackOutboundLink = function (url) {
    ga('send', 'event', 'Outbound Links', 'click', url, {
        'hitCallback':
          function () {
              document.location = url;
          }
    });
}

Open in new window


Of course, on all my outbound anchors I have onclick attributes:
<a href="http://www.mywebsite.com" onclick="trackOutboundLink('http://www.mywebsite.com'); return false;" target="_blank">Track This Outbound Link</a>

Open in new window


You change the parameters in the ga() function call to record different things.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 40857075
@webdirexion

Have you tried the code I posted?
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now