Solved

javascript custom events tracking code

Posted on 2015-02-24
2
94 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
Suggested Courses

624 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