Solved

Need Help with Google Analytics Outbound Link Tracking JavaScript.

Posted on 2014-07-26
7
464 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I got it  working.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

9 Experts available now in Live!

Get 1:1 Help Now