Solved

Need Help with Google Analytics Outbound Link Tracking JavaScript.

Posted on 2014-07-26
7
475 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now