Google Analytics

Tracking PayPal with Google Analytics and Google AdWords

Setting up ecommerce tracking is essential if you are selling online (if you don't sell online check out Monetizing Non-Ecommerce Sites). But not all ecommerce systems integrate with Google Analytics. And if you are selling online chances are you accept PayPal® as a method of payment. So how do  track visitors who have purchased via PayPal?


First step, create a thank you page for successful PayPal transactions and set that URL within PayPal so visitors are returned to your site.



The problem is that when the visitor returns to your site after payment has been received (or cancelled) PayPal gets the credit for the conversion and not the original way the visitor found your site.

Steps For Tracking PayPal With Google Analytics:

1. Log into PayPal.

2. Under the 'My Account' tab click on the 'Profile' link.

3. Click on 'Website Payment Preferences' (under 'Selling Preferences' in the right column).

4. Turn 'Auto Return' on and enter the URL of your PayPal thank you page.

Then add ?utm_nooverride=1 to the end of your URL (highlighted in blue below), this will ensure that transactions (i.e. conversions) are credited to the original traffic source, rather than PayPal.



For example, if a visitor came from a Google search for 'gardening book' the conversion will be credited to Google, organic, gardening book (and not PayPal, referral).

At this point if you simply want to track the conversions using goals you can setup a new goal for the thank you page within Google Analytics. However, if you want to also get Google Analytics ecommerce tracking up and running you will need to get a little more technical.

PayPal's payment data transfer allows you to receive transaction details once a visitor is back on your site (visit the PayPal technical overview article for details).

Getting Advanced With Ecommerce Tracking:

6. Turn 'Payment Data Transfer' on.



Please note that once you turn on 'Payment Data Transfer' it will be applied to all Auto Return payments unless otherwise specified within the button or link for that Website Payment.

7. You will now either have to create your 'Buy Now' buttons or modify your existing buttons.

If you are creating new 'Buy Now' buttons leave the return URL blank (or if you specify a different URL ensure it has ?utm_nooverride=1 at the end).

If you already have buttons on your site you will need to look for the following code:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

And add the following before the </form> element (with your correct thank you page URL):

<input name="return" type="hidden" value="http://www.site.com/paypal-thanks.php?utm_nooverride=1" />

8. Finally you will need to modify your thank you page to grab the PayPal data being transfered using either the POST of GET methods (you will have to talk to your web developer or IT person if you are not familiar with the coding of your site).

Basically, you will need the Google Analytics ecommerce tracking code to automatically (or dynamically) grab the correct values and place them in the code. You will be able to get total price, tax, shipping, transaction id, item name, quantity, etc.

Example Google Analytics Ecommerce Tracking Code:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._trackPageview();
pageTracker._addTrans(
"6NB836968U296223E", // Order ID
"", // Affiliation
"20.00", // Total
"2.00", // Tax
"0.0", // Shipping
"", // City
"", // State
"" // Country
);
pageTracker._addItem(
"6NB836968U296223E", // Order ID
"ProductId123", // SKU
"Green T-shirt", // Product Name 
"T-Shirts", // Category
"20.0", // Price
"1" // Quantity
);
pageTracker._trackTrans();
} catch(err) {}
</script>

For Google AdWords conversion tracking you simply need to grab the total value and pass that into the conversion script as the value.

Example Google AdWords Conversion Tracking Code:

<script type="text/javascript">
<!--
var google_conversion_id = 12345678;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "U10bCNfstvhghO6gM";
var google_conversion_value = 0;
if (20) {
  google_conversion_value = 20;
}
//-->
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/12345678/?value=20&label=U10bCNfstvhghO6gM&guid=ON&script=0"/>
</div>
</noscript>

Read about Google Analytics ecommerce tracking

Read about Google AdWords conversion tracking

Finally, we strongly recommend that you test everything out using the PayPal Sandbox.


If you have any questions please feel free to contact us directly and if you are located in Australia check out our Google Seminars for Success for the best Google Analytics training available!

Thanks to ROI Revolution for inspiring this post who originally discussed Google Analytics and PayPal back in 2007.

32 comments:

  1. GREAT article! Thats all i can say...

    ReplyDelete
  2. Wonderful! Thank you for posting this.

    ReplyDelete
  3. Can you use this information for "add to cart" buttons or simply "buy now" buttons?

    Rick

    ReplyDelete
  4. Hi Rick,

    Thanks for the question.

    It shouldn't be a problem. Try adding the code to your "add to cart" button.

    If you have any problems feel free to get in touch (www.mangoldsengers.com/contact-us).

    Regards,
    Benjamin Mangold

    ReplyDelete
  5. The e-commerce tracking code is working fine, however all the data comes as referrer (Paypal). Is there a way where i can actually track and separate paid and non paid data or organic and non organic data. Any help would be grateful.

    ReplyDelete
  6. Hi Anonymous,

    It sounds like you haven't added ?utm_nooverride=1 to the end of your thank you page URL.

    Ensure you have completed step 7 in the post.

    Regards,
    Benjamin Mangold

    ReplyDelete
  7. Hi Benjamin,

    Thanks for the quick response.

    In the form variable do we need to include the return URL as we have mentioned it in the paypal account settings which is in the following format - http://www.yoursite.com/thankyou.html?utm_nooverride=1.

    Will this help us to get traffic data i.e. direct or organic or paid and not only as referral traffic.

    ReplyDelete
  8. I believe that should do the trick.

    basically adding ?utm_nooverride=1 will ensure the credit for the conversion goes to the original source/medium for the visitor (rather than being overwritten by PayPal as a referral).

    Let me know how you go!

    Regards,
    Benjamin

    ReplyDelete
    Replies
    1. Hi Benjamin,
      We're having trouble tracking all of our sales.
      When the payer has a paypal account, the auto return will work and the sale will be registered.
      However, when the payer pays by credit card, the payment goes through paypal but the sale will be registered only if the payer hits the button "back to merchant site" which they never do.
      Paypal has confirmed that auto return will work only with paypal user's.
      Do you know what we can do to track all our sales?

      Delete
  9. What if the customer closes how browser before he is redirected back to my site?

    ReplyDelete
  10. Hi Benjamin,

    We have implemented all the steps as per the recommendations made by you. However we are still getting data as referral traffic. Is it because the entire checkout process has "https" URLs while the rest of the site has http URLs. Is this the reason why E-commerce is not working properly. Can you please provide us an alternate solution so that proper data is tracked and not only as referral traffic.

    ReplyDelete
  11. Hi Mydogtag.ca,

    If a visitor closes their browser (or does not make it to the thank you page on your site) then the conversion will not be reported in Google Analytics.

    There is really only one other choice in this scenario and that is track the conversion on the outbound click to PayPal.

    The downside of this is that your conversions will be inflated.

    Thanks for the question!

    Regards,
    Benjamin

    ReplyDelete
  12. Hi Anonymous,

    Regarding referral traffic problem - it is difficult to guess at what the cause of this is. Could you give us an example of a page where you have implemented the solution.

    If you don't want to share this in these comments you can complete our contact form at www.mangoldsengers.com/contact-us - just ensure you mention that you have posted in the comments of this post.

    Regards,
    Benjamin

    ReplyDelete
  13. Benjamin,
    Does the auto return from PayPal back to the site only work for buyers who have an actual PayPal account (and not for buyers who enter a credit card into PayPal)?

    I saw that explanation at http://www.google.com/support/forum/p/AdWords/thread?tid=433e0ebab1c6bd9d&hl=en
    (SosieBear's post on 5/6/10).

    Regards,
    Laura

    ReplyDelete
  14. We use only Paypal buy now buttons.

    The problem that I'm having is that Paypal only Auto-Returns if the customer has a paypal account. If they simply choose to use a credit card and NOT become a Paypal member, Paypal will not auto-return them to our final thank you page. Therefore we can't always track conversions.

    Considering we only care about tracking conversion in Adwords, will your method work for our scenario?

    ReplyDelete
  15. According to PayPal's own documentation on auto return;

    "Auto Return applies to all PayPal Website Payments, including Buy Now, Donations, Subscriptions, and Shopping Cart."

    I will see if I can find any more details and post another comment.

    Thanks,
    Benjamin

    ReplyDelete
  16. Okay, so if someone pays with a credit card and does not have a PayPal account then they are not automatically redirected to your thank you page. Apparently they have to click a link to return to the website.

    I haven't been able to find this officially noted by PayPal, it only appears on a few forum posts from users who say it is some type of legal requirement that PayPal must stick to.

    Also check to ensure you are using Website Payments Standard - apparently auto return only works with this type of payment.

    Possible solutions/compromises:

    (1) Prevent payments via credit card (probably not a great idea because we all want to be paid in the quickest, easiest manner).

    (2) Tell people to click 'return to merchant' if they pay with a credit card (this could be placed on the last step before they get sent to PayPal).

    (3) Create a backup goal that logs the outbound click to PayPal (be prepared for inflated goal conversions).

    (4) Tell PayPal they should update their documentation and that they should allow auto return on credit card payments!

    And for the more technical...

    (5) Use IPN (Instant Payment Notification) to trigger an email to get people to the thank you page or somehow trigger the goal conversion.

    The last one is not something I have personally played with, but should be technically possible. I might get our team to have a look at this and see what is possible.

    I hope that gives you a few ideas - if you think of any more please let me know or post them.

    ReplyDelete
  17. Hello Benjamin,

    thanks for the very clear instructions.

    Question n°1:

    Will the Google Analytics ecommere tracking code work with a hosted buy now button (hosted on Paypal)?

    I'm using product specific buy now buttons hosted on Paypal and product specific thank you pages on unique urls.

    Using Paypal hosted buttons means the next piece of code is ABSENT in my button's code (the code on my pages) : input name="return" type="hidden" value="http://www.site.com/paypal-thanks.php?utm_nooverride=1" />

    Is adding ?utm_nooverride=1 at the end of the return urls, inside the Paypal configuration panel for buy buttons a solution? Which means that the return url "http://www.site.com/paypal-thanks.php?utm_nooverride=1" will also be hosted on paypal.

    Question n° 2:

    Quote: 8. Finally you will need to modify your thank you page to grab the PayPal data being transfered using either the POST of GET methods (you will have to talk to your web developer or IT person if you are not familiar with the coding of your site).

    Basically, you will need the Google Analytics ecommerce tracking code to automatically (or dynamically) grab the correct values and place them in the code. You will be able to get total price, tax, shipping, transaction id, item name, quantity, etc.


    What do you mean? Isn't adding the analytics ecommerce tracking code on the thank you page enough?

    Thank you in advance,

    Nick

    ReplyDelete
  18. Hello Benjamin,

    I posted a comment on august 27. Can you check it, please. I'm still very interested in your answer.

    Sorry for pushing you...

    Nick

    ReplyDelete
  19. Hi Nick,

    Regarding your questions...

    (1) I haven't used buttons hosted on PayPal, so I would strongly recommend testing the solution out. Try creating a new button (just for testing) and add the parameter to your destination page URL.

    In theory it should work correctly because if someone comes to your site, clicks the button (which is hosted), gets taken to PayPal and then returns to your site with the parameter added to the end of the URL – they will keep their original source/medium and it won't be overwritten as a referral from PayPal.

    In order to test this, create a hidden page (i.e. not public) with the hosted test button. Then visit your site with some fake campaign tags (e.g. http://www.site.com?utm_campaign=TEST&utm_source=TEST&utm_medium=TEST) this will set a cookie with the 'TEST' values. Click on to PayPal and complete a test transaction and then when you return to your site you should check your cookies and they should still have the 'TEST' values.

    (2) The Google Anlaytics ecommerce code needs to contain the correct values for the particular transaction, so if someone purchases 10 mugs with a total value of $100 those details need to be within the tracking code.

    This is something your web developer will have to help you with because it requires programming. That being said, it should not take your web developer long to get this done.

    I hope that helps! (And thanks for reminding me to comment!)

    Regards,
    Benjamin

    ReplyDelete
  20. Thanks for this valuable article, but iam confused because i have 2 different sites on my paypal account which all together are different products with different costs and goal value.
    So my question is how would i make 2 thankyou pages because in paypal it suggest only one URL in auto return therefore i can only setup one eCommerce tracking code on thank you page. Adding both goal values in same tracking thankyou page is iam sure not suggested by any means.
    Thanks! Vincent

    ReplyDelete
  21. Hi just wondering if you also have sample of paypal and analytics integration using c#. Thanks.

    ReplyDelete
  22. Hello Benjamin,

    We are promoting an ebay store via Google adwords. We want to track ebay store conversions via adwords. Is this possible?

    ReplyDelete
  23. Hi Vincent,

    Unless PayPal has added the ability to add multiple thank you pages (which I am guessing they haven't). Then your options would be to create a separate PayPal account for the separate website, only track one or you could fire off a conversion into two Google Analytics accounts on the thank you page. But this option isn't a good one because you will have double the number of conversion spread across the two Google Analytics accounts.

    So creating a separate PayPal account is probably the best option.

    ReplyDelete
  24. @Anonymous Unfortunately we don't have a c# integration we can share with you.

    @Hemi Once you have conversions tracking into Google Analytics you can then either import that data into Google AdWords. But the simplest option would be to just place the Google AdWords conversion script onto the thank you page. This will give you the total number of conversions. Tracking value has the same issues as described in the post and comments above.

    ReplyDelete
  25. Hi Benjamin,

    Thanks for all your hard work.

    I notice there seems to be two places to add the returning URLs and I wonder if one overides the other. In Selling preferences as you say, you can enter the returning thank you page and added code, but when you create a button for a product, there is also a "customise advanced Features" drop down before you are given the html button code. Here you can once again give a returning URL. Does this overide the other one if completed? We have created a different return landing page for every product to match the returning url created in the button. Did I waste my time, could I have used the overide code and just had one returing thank you page? This is getting way above my head!!! Sharon

    ReplyDelete
  26. I'm not sure I understand step 8. I think it means I will need to either hardcode values into the script, or somehow pull them from a querystring or post. Could someone elaborate please?

    Thanks..

    ReplyDelete
  27. The only part I am unsure about is the Google Analytics Ecommerce Tracking Code.
    I am not sure how to add this to the page. I understand I add the code to the page but every example shows data included. Do I just remove the parts like price etc as I have many different products on the website. I know there is probably a really straight forward answer but just cant get my head round it.

    ReplyDelete
  28. rgsamways and James, you’d need to find out what the variable names are that are passed onto the thank-you page (or whatever page you've got the tracking code on), and then add them to the ecommerce tracking code.

    Eg:

    pageTracker._addTrans( “1234″, // Order ID”Sea View”, // Affiliation

    “$total″, // Total

    “$tax″, // Tax

    The above would work if the variable name for the total cost was $total, for example.

    With that said, I don't know what variable names Paypal uses - perhaps someone else could share that information?

    ReplyDelete
  29. I just found this for Paypal variables, which should help: https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables

    ReplyDelete
  30. Thanks for this post. I was looking for an example and bingo. Can't wait to implement. Cheers!

    ReplyDelete
  31. Thanks Ben, I'm a little confused with steps 7 and 8. I'm on a wordpress site using a third party shopping cart system.

    1. I've added the extension to the URL in Paypal preferences - do I now need to add the extension to the URL on the thank you page as well?

    2. If not using paypal's buy now buttons but custom ones, do you still need to edit the buttons in any way?

    3. i want to track conversions in both adwords and analytics. Is the updated tracking code dependent on the "payment data transfer" being turned on in Paypal? i don't see what the point of that is, and not sure how to turn it on in wordpress.

    Thanks for the great article.

    ReplyDelete