Solved

Need Help with Google Analytics Outbound Link Tracking JavaScript.

Posted on 2014-07-26
7
482 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
  • 4
7 Comments
 
LVL 109

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

776 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