Practical Ecommerce

Google Analytics: How to Track PayPal Transactions

It is a headache tracking PayPal transactions in Google Analytics. There are currently no options for placing Google Analytics tracking code on PayPal’s pages. This makes the measurement of conversions and acquisition sources in Google Analytics challenging when customers pay with PayPal.

Difficulties with Measuring PayPal

Typically, PayPal transactions are only measured in Google Analytics when customers complete purchases through PayPal and then return to the order confirmation page on a website. In this scenario, ecommerce tracking is triggered, sending sales information to Google Analytics in about 90 percent of the time, in my experience.

The problem of lost customer information tracking in Google Analytics occurs when customers close the PayPal page after completing the payment.

Merchants are more likely to overestimate conversions when measured before sending users to PayPal, as some shoppers will abandon the PayPal page before finalizing. Conversely, if customers are tracked returning to the order information page, the total number of PayPal conversions that Google Analytics reports will likely be underestimated, as certain customers will not return to that page.

How to Connect PayPal with Google Analytics

The first way to track PayPal conversions in Google Analytics is to redirect users who have made a purchase via PayPal to the merchant’s order confirmation page. Here are the implementation steps:

  1. Log into your PayPal account;
  2. Click on the “Profile” link located under the “My Account” tab;
  3. Click on “Website Payment Preferences” found in the right-hand column under “My Selling Tools”;
  4. Set “Auto Return” to ON and enter the URL of your ecommerce thank-you page;
  5. Add “?utm_nooverride=1” to the end of your URL. This ensures that transactions (i.e., conversions) are credited to the original traffic source rather than to PayPal.
    PayPal Auto Return for website payments.

    Set “Auto Return” to ON and enter the URL of your ecommerce thank-you page.

If you are set up in Universal Analytics, there is no need to add “?utm_nooverride=1.” Instead, just add PayPal.com to your “Referral Exclusion List” within the Admin section located under “Property” and “Tracking Info.”

At this point, if you only want to track the conversions using goals, you can set up a new goal for the thank-you page within Google Analytics. If, however, you also want to get Google Analytics ecommerce tracking up and running, you will need to get a little more technical and implement the following steps.

  1. Enable Payment Data Transfer (PDT) in your PayPal account. This allows you to transfer payment details (the item purchased, the transaction amount, geographical location of the buyer) to your website domain. 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.
  1. Create your “Buy Now” buttons (or modify your existing buttons) and include specific PayPal variables in Buy Now buttons on your product pages.

Leave the return URL blank if you are creating new Buy Now buttons. If you already have buttons on your site, you will need to look for the following code snippet.

Look for this code snippet.

Look for this code snippet.

Then, add the following code before the element (with the correct thank-you page URL).

Add this code before the element.

Add this code before the element, with the correct URL.

  1. Modify your “thank-you” page to retrieve the PayPal data that will be transferred using either the POST of GET methods. You will need the Google Analytics ecommerce tracking code to grab the correct values and place them in the code snippet automatically. You will then be able to get total price, tax, shipping, transaction id, item name, quantity, and other variables.
    Example of Google Analytics ecommerce tracking code.

    An example of Google Analytics ecommerce tracking code.

Measuring PayPal Transactions with PayPal’s Instant Payment Notification

The second way of measuring PayPal transactions is using the PayPal’s Instant Payment Notification (IPN), which automatically sends you each transaction’s details.

The process is a complicated in that it requires passing transaction details to Google Analytics, which you can do with the Measurement Protocol. Using the IPN service and the Measurement Protocol, we can measure transactions made via PayPal in Google Analytics.

Configuring Zapier for PayPal Tracking

One of the services for connecting PayPal with Google Analytics is Zapier. It helps accept IPN details for each transaction and then submits them to Google Analytics.

Let’s walk through the process of creating a “Zap” that will send each transaction’s data to Google Analytics. First, create a testing property to ensure it works correctly. You should also use PayPal’s sandbox to test transactions.

  1. Create a new Zap. A Zap is a specific link between two services that Zapier connects. Begin by creating a new Zap for PayPal.

When a customer makes a purchase, Zap sends this data to the webhook. In the drop-down menu under PayPal, select “successful sale” (trigger). You will also need to select “Custom Request” (action) for the webhook (located under “Show all actions”).

Use Zapier to connect PayPal with Google Analytics.

Use Zapier to connect PayPal with Google Analytics.

  1. Add the webhook to your PayPal account. Zapier will provide a URL that accepts details about transactions coming from PayPal’s IPN. You can add it to your PayPal account to send all transactions to Zapier or just add it to a particular “buy now” button that you created.

Here is what saving a URL in PayPal’s settings looks like.

Saving a URL using Zapier.

Saving a URL using Zapier.

First, copy the URL shown on the screen into your clipboard. Then, navigate to your PayPal IPN Settings. The easiest way to get there is by clicking on the PayPal IPN settings link inside Zapier and opening it in a new tab or window.

PayPal IPN Settings link inside Zapier.

PayPal IPN settings link inside Zapier.

After logging into PayPal, click the “Choose IPN Settings” button and then paste the URL you copied earlier. Enable notifications and then click “Save.”

Paste the Zapier URL into PayPal and enable notifications.

Paste the Zapier URL into PayPal and enable notifications.

Your settings should now look like this, with your URL instead of the one shown in the screenshot.

PayPal Notification URL.

PayPal Notification URL.

To add the IPN URL to a “buy now” button, use the JavaScript button and then click “Customize” to add the “data-callback” element, as follows.

<script async="async" src="https://www.paypalobjects.com/js/external/paypal-button.min.js?merchant=you@company.com"
data-button="buynow"
data-name="My product"
data-amount="1.00"
data-callback="https://zapier.com/hooks/paypal/?cid=56789">
</script>

  1. Add a custom filter in Zapier. Custom filters are ideal for ensuring Zaps trigger only on specific items. You’ll need to add a custom filter in Zapier to ensure that there’s a value set for PayPal’s custom value before sending data to Google Analytics.
    Add a customer filter in Zapier.

    Add a customer filter in Zapier.

  1. Construct the Google Analytics hit. The second part of the integration process involved data transfer from Zapier to Google Analytics using the Measurement Protocol. We first need to create a data hit, which will be sent to Google Analytics through the Measurement Protocol. Change the Google Analytics property ID (UA-123456-1) to your actual property ID number (where the data hit is sent).
  1. Enable Enhanced Ecommerce in Google Analytics. You need to enable “Enhanced Ecommerce” in your Google Analytics account. Go to the “Admin” section and click on “Ecommerce Settings” in the view settings.
  1. Check and modify your code. With the latest version of the Google Analytics Tracking Code installed, include the following code snippet to all the pages with PayPal “buy” buttons.

<script type="text/javascript">
function _uGC(l,n,s) {
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i,i2,i3,c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
c=l.substring((i+i3),i2);
}
return c;
}
var uaGaCkVal= _uGC(document.cookie, '_ga=', ';');
var uaGaCkValArray= uaGaCkVal.split('.');
var uaUIDVal="";
var gacid="";
if(uaGaCkValArray.length==4) {
uaUIDVal=uaGaCkValArray[2] + "." + uaGaCkValArray[3];
gacid='=' + uaUIDVal.replace(/%2F/g,"-");
}
else {
uaUIDVal="";
gacid="";
}
var myNewValue = gacid;
</script>

This code above — which comes from LovesData.com — takes details from the Google Analytics cookie on a user’s browser and passes it on to the PayPal button.

  1. Modify buy-now buttons. You will need to modify the PayPal “buy-now” buttons to include the custom data input. Also, add IPN details to the button code, as follows.

<script async="async" src="https://www.paypalobjects.com/js/external/paypal-button.min.js?merchant=you@company.com"
data-button="buynow"
data-name="My product"
data-amount="1.00"
data-custom=unknown
data-env="sandbox"
data-callback="https://zapier.com/hooks/paypal/?cid=56789">
</script>

Change the URL for “data-callback” above to the URL provided in Zapier. Finally, when the code is added to your live site remember to remove data-env=”sandbox” from the code snippet above.

  1. Test and save. Complete a PayPal transaction to test your Zap. Your customer campaign tags should display in Google Analytics if the test works correctly.

Configuring Zapier for PayPal Tracking Using Google Tag Manager

Tracking PayPal through Google Tag Manager follows a similar structure as described above. Note that the tag type in the HTML container must be Universal Analytics.

The tag type in the HTML container must be Universal Analytics.

The tag type in the HTML container must be Universal Analytics.

Include the following code snippet in the HTML container.

<script type="text/javascript">
function _uGC(l,n,s) {
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i,i2,i3,c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0) { i2=l.length; }
c=l.substring((i+i3),i2);
}
return c;
}
var uaGaCkVal= _uGC(document.cookie, '_ga=', ';');
var uaGaCkValArray= uaGaCkVal.split('.');
var uaUIDVal="";
var gacid="";
if(uaGaCkValArray.length==4) {
uaUIDVal=uaGaCkValArray[2] + "." + uaGaCkValArray[3];
gacid='=' + uaUIDVal.replace(/%2F/g,"-");
}
else {
uaUIDVal="";
gacid="";
}
var myNewValue = gacid;
</script>

Tracking True Referrals with PayPal

Whenever a customer leaves your website to make a payment via a third-party payment gateway and later returns to your site from the gateway, Google Analytics will often attribute sales to the payment gateway instead of to the original traffic source. This is common in PayPal’s case. You can often find PayPal.com appearing as a top referrer in Google Analytics’ Referral report:

PayPal.com appearing as a top referrer in Google Analytics’ Referral report.

PayPal.com appearing as a top referrer in Google Analytics’ Referral report.

The best way to track original referrals while using offsite, third-party payment gateways — when customers must leave your website to complete the transaction — is not to use offsite gateways.

If you use direct payment gateways, your customers can complete transactions without leaving your website. As mentioned earlier, PayPal is quite easy to set up and convenient for the receipt of funds, so you might not want to avoid its use.

You have a few options in that case.

First, you can add PayPal to the referral exclusion list, but it won’t help you track the original referrer. The other point worth noting is that referral exclusion does not work retroactively.

Add PayPal to the referral exclusion list.

Add PayPal to the referral exclusion list.

Second, you can add event-tracking code to the PayPal “Buy Now” button. PayPal provides you with a button code snippet that you can edit and embed on your website.

PayPal event tracking code.

PayPal event tracking code.

Whenever the PayPal button is clicked, the event code records the action and sends the click data to Google Analytics.

You should be able to use your event tracking report to determine the original traffic source by applying “Source/Medium” as a secondary dimension:

Use event tracking report to determine the original traffic source.

Use event tracking report to determine the original traffic source.

You will at least see where these PayPal transactions have come from regardless of whether a user completed the purchase after clicking the PayPal button.

Putting It All Together

Once you put everything together, you should start to see PayPal transaction data in your Google Analytics’ sales report.

PayPal transaction data in GA sales report.

PayPal transaction data in Google Analytics sales report.

The custom code that was added to pages uses the Client ID (CID) value from your Google Analytics cookie and sends it to PayPal. The CID is retrieved from Zapier and sent along with transaction data to Google Analytics.

This ensures that Google Analytics has a full view of the entire transaction, as if it had occurred on your website without the person ever leaving.

Zapier is the easiest way to connect PayPal with Google Analytics, so as not to lose information about transactions and to estimate the number of conversions and revenue gained from those transactions.

Kunle Campbell
Kunle Campbell
Bio  |  RSS Feed


Get the Practical Ecommerce RSS feed

Comments ( 9 )

  1. Alison Groves August 11, 2015 Reply

    This is incredibly cool, Kunle, thanks for sharing! Amazingly inventive use of Zapier, for sure.

  2. B. Moore August 12, 2015 Reply

    Would love to see a tutorial made to get this working on a Magento site.

  3. Felix August 12, 2015 Reply

    Great stuff, Kunle! Will be sharing this.

  4. Loves Data August 12, 2015 Reply

    Hi Kunle,

    Thanks for sharing our solution with your readers, we’re glad it worked for you too. It’s one step closer to bridging the gap between PayPal and Google Analytics which means we’re on the right track.

  5. David Rothwell August 13, 2015 Reply

    Fantastic article! Many thanks.

  6. Julian Joseph October 18, 2015 Reply

    Hi Kunle,

    Thanks for this. Will it continue to populate data in GA if the donation is recurring?

  7. Michael March 2, 2016 Reply

    Hi Kunle, thank you for the article, the information is very helpful. When tracking true referrals with Paypal, if we’ve added event tracking code to the button, then do we still add paypal to the referral exclusion list? Or is that not necessary since we wouldn’t be able to see paypal as a source anymore in analytics?

  8. Shaun Burgess March 23, 2016 Reply

    A similar article from these guys http://www.lovesdata.com/blog/2014/paypal-google-analytics/ mentions a bug ie. ” Construct the Google Analytics Hit

    Now we need to create the hit that we send to Google Analytics using the Measurement Protocol. There are two important things to be aware of. Firstly, you will need to change UA-123456-1 to your own Google Analytics Property ID as this is where the data will be sent. Secondly, you will notice that there is an incorrectly formatted query parameter of cidCustom, this isn’t actually a mistake, so make sure it looks exactly like that in your Zap configuration (even though logic would tell you to use cid=Custom, this will not work).” Do you know if fixed or do you also recommend altering the cid=Custom to cidCustom in Zaps due to the bug? Regards Shaun

  9. Prashabh May 26, 2016 Reply

    Very useful article, thank you for such a vital information.

Email Newsletter Signup

Sign up to receive EcommerceNotes, our acclaimed email newsletter.
And receive a free copy of our ebook
50 Great Ecommerce Ideas