Solved

Need Help with Google Analytics Outbound Link Tracking JavaScript.

Posted on 2014-07-26
7
507 Views
Last Modified: 2016-02-24
Hello,

I have a blog and a plug-in that allows me to build bundles for Amazon items. I have the site track outbound links with the following javascript code to track in Google Analytics:

<script type="text/javascript">// <![CDATA[
/* Attach tracking to all download & external links */
var _gaq = _gaq || [];

function _gaLt(event){
        var el = event.srcElement || event.target;

        /* Loop up the tree through parent elements if clicked element is not a link (eg: an image in a link) */
        while(el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || !el.href))
                el = el.parentNode;

        if(el && el.href){
                if(el.href.indexOf(location.host) == -1){ /* external link */
                        _gaq.push(["_trackEvent", "Outgoing Links", el.href, document.location.pathname + document.location.search]);
                        /* if target not set delay opening of window by 0.5s to allow tracking */
                        if(!el.target || el.target.match(/^_(self|parent|top)$/i)){
                                setTimeout(function(){
                                        document.location.href = el.href;
                                }.bind(el),500);
                                /* Prevent standard click */
                                event.preventDefault ? event.preventDefault() : event.returnValue = !1;
                        }
                }

        }
}

/* Attach the event to all clicks in the document */
var d = document;
d.addEventListener ? d.addEventListener("click",_gaLt,!1) : d.attachEvent && d.attachEvent("onclick",_gaLt);
// ]]></script>

Open in new window

This code works great tracking most of my outbound links however the "buy now" button that this plug-in builds is not getting tracked. Can somebody show me what I need to update my code to to get it to track the buy now button on the following page?

http://www.largeoutdoorstoragesheds.com/blog/lifetime-8x10-storage-shed-windows-skylights-shelving-shutters-bundle/
0
Comment
Question by:smower
[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
  • 4
7 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40222981
No points for this, but with a "buy now" button you wouldn't really be tracking clicks, you would be fulfilling orders, right?
0
 

Author Comment

by:smower
ID: 40223865
I wouldn't be fulfilling those. They are fulfilled by Amazon if the customer completes checkout at Amazon. I just want to know when people click that button. That button is created by a wordpress plugin so I don't know a way to modify it and need some on the fly JavaScript to tag it or something.
0
 

Author Comment

by:smower
ID: 40245262
If I can't get the actual link, is there a way to just get an event that they clicked on the button?  It seems very doable but my javascript experience isn't that great.
0
 

Accepted Solution

by:
smower earned 0 total points
ID: 40247889
I discovered that this can be done with Google tag manager. I set up a click event tracking code and narrowed it down to the element ID.
0
 

Author Closing Comment

by:smower
ID: 40255154
I got it  working.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
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)

615 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