Solved

javascript custom events tracking code

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

710 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