Track a PayPal Form Event with Google Analytics

Alt Text

This page will tell you how to get the Google Analytics data of people that click on a PayPal button.

1. Add the correct Google Analytics code into your site

Add the new tracking code from Google into your header tag.

Taken from the Google site: “Copy the following code, then paste it onto every page you want to track immediately before the closing </head> tag.” (You will have to add your own Account number ‘XX-XXXXXX-X’)

<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'XX-XXXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>

2. Add the “event tracking” code into your PayPal form

This is the “event tracking” code:

onClick="_gaq.push(['_trackEvent', 'One', 'Two', 'Three']);"

This is the PayPal form code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="XXX">
<input type="hidden" name="hosted_button_id" value="XXX">
<input type="image" src="buy.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

And here is the google tracking code and the PayPal form together:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onClick="_gaq.push(['_trackEvent', 'One', 'Two', 'Three']);">
<input type="hidden" name="cmd" value="XXX">
<input type="hidden" name="hosted_button_id" value="XXX">
<input type="image" src="buy.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

3. All done!

Load the page (checking “view source” to make sure the new code is there). Click your “buy” button and then wait. I find Google Analytics takes about an hour to update the analytics information

To find the event information in Google Analytics: click “Content” then click “Event Tracking” on the left hand side menu

4. Custom Reporting in Google Analytics

Check out this video on how to create custom reports for your events.

One thought on “Track a PayPal Form Event with Google Analytics

  1. Thanks for this. It worked great for me. The other site I found was instructing users to place the onClick= string within this line of code: , which did not work.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>