JQuery waypoints with analytics tracking getting page URL
I am trying to implement a tracking event for when my user scrolls to the bottom of an article page on my website using JQuery waypoints plugin (http://imakewebthings.github.com/jquery-waypoints/), but am having trouble firing the event when I bring the URL of the page into the event. It works fine without the URL, but the URL of the page is needed so I can see which article is being read.
It is also a requirement that the event is only fired once per visit (which is what the event.stopPropagation();}, {triggerOnce: true,offset: 'bottom-in-view'}); is for.
The JQuery code is below:
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.min.js"></script>
<script src="http://www.simonholmes.co.uk/js/waypoints.min.js"></script>
<script type="text/javascript">
$(document).ready(function(event) {
$('#lcol2').waypoint(function() {
var Page开发者_运维知识库URL = window.location.pathname;
_gaq.push(['_trackEvent', 'Article Test Event', 'Scrolled to end of article', PageURL ,'DATA HERE']);
event.stopPropagation();
}, {
triggerOnce: true,
offset: 'bottom-in-view'
});
});
</script>
Thanks for any ideas and help,
Simon
Sometimes you need to convert a location object so it can be consumed as a string.
var PageURL = window.location.pathname + "";
I found the problem, it was in the
_gaq.push(['_trackEvent', 'Article Test Event', 'Scrolled to end of article', PageURL ,'DATA HERE']);
part of the code. The final variable 'DATA HERE' had to be either be an integer, or left blank as stated in http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html, and not a string, which was causing the event to not work.
Thanks for your help anyway Diodeus.
精彩评论