Reputation: 12588
I am trying to track clicks on a Paypal order button, my code looks like this....
<form onclick="_gag.push(['_trackEvent','Category','Action','Label']);" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="FV4TYGHXWUGHT">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Test Item">
<input type="hidden" name="amount" value="5.00"><input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="custom" value="">
<input type="hidden" name="notify_url" value="http://www.mydomain.com/notify.html">
<input type="hidden" name="return" value="http://www.mydomain.com/return.html">
<input type="image" src="http://www.mydomain.com/images/buynow.png" name="submit"/>
<img style="margin-top:20px;" alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
This doesn't work and no event is fired when clicked, analytics is working fine on the page other wise and if I use this....
<a href="http://www.testurl.com" target="_blank" onclick="_gaq.push(['_trackEvent', 'Click-Through', 'Test1', 'Test2']);">TEST LINK</a>
It works fine and I can see the event reported in realtime analytics
Can anyone see what I am doing wrong?
Upvotes: 2
Views: 633
Reputation: 2383
I think the problem you are facing that the page navigation happens before GA has had the time to fire the event. You can use the example provided on this page to solve your problem.
First, Add following to the head:
<script type="text/javascript">
function trackOutboundLink(form, category, action, label) {
try {
_gaq.push(['_trackEvent', category , action, label]);
} catch(err){}
setTimeout(function() {
form.submit();
}, 100);
}
</script>
Then, Change your tracking as follows:
<form onsubmit="trackOutboundLink(this, 'category', 'action', 'label'); return false;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
**Note that I have not tested this but I know that something like this should work. Once you try this and it does not work, let me know and I can find if something is wrong here.
Upvotes: 4
Reputation: 9603
EDIT: onclick is a valid attribute for a form, I would still use onsumbit. Instead of placing the onsubmit on the <form>
tag itself, place it on the input
<input type="image" onclick="_gag.push(['_trackEvent','Category','Action','Label']);" action="https://www.paypal.com/cgi-bin/webscr" src="http://www.mydomain.com/images/buynow.png" name="submit"/>
Upvotes: -1