Solved

javascript custom events tracking code

Posted on 2015-02-24
2
85 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

803 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