Is it possible to connect Paypal and Google Analytics?

I want to know what website is leading to sales of my product.

For each sale, I want to know what external website the buyer was directed from.
(Example: If all of my sales come from Facebook, I can concentrate more on the work I do on that site.)

My Site: SNIP
Thank you

Dani AI

Generated

Yes, but do not rely on buyers clicking back to your site. is right that a thank-you page works only when PayPal Auto Return actually fires; and as saw, Auto Return does not auto-redirect for guest checkouts when “PayPal Account Optional” is on, so many buyers will just close the window. That is expected behavior per PayPal’s docs. (paypal.com)

A reliable approach is server-side. Before sending someone to PayPal, store their GA client_id and UTMs; pass them through the transaction using PayPal’s passthrough fields: custom for Standard buttons or custom_id/invoice_id if you use the Orders API. PayPal includes those values in its payment notifications (IPN or Webhooks), so your server can tie the payment back to the original session/source even if the user never returns. Then post a GA4 purchase event via the Measurement Protocol using that client_id (do not send PII). (developer.paypal.com)

Example (server-side) to record the sale in GA4 after you receive the PayPal notification:

curl -X POST \
  'https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXX&api_secret=YOUR_SECRET' \
  -H 'Content-Type: application/json' \
  -d '{
    "client_id": "GA_CLIENT_ID_FROM_PAYPAL_CUSTOM",
    "events": [{
      "name": "purchase",
      "params": {
        "transaction_id": "PAYPAL_TXN_ID",
        "value": 49.00,
        "currency": "USD"
      }
    }]
  }'

See GA4’s Measurement Protocol guide and purchase event reference for required parameters and limits. (developers.google.com)

Two more tips: 1) Add paypal.com to GA4’s List unwanted referrals so any users who do return are not attributed to PayPal but to the original source. 2) Keep your thank-you page tracking as a backup, but let the server-side event be your source of truth. ()

Recommended Answers

All 5 Replies

I think you can if you set it up on Google Analytics to track particular goals and one goal is that visitors visit the pay with the paypal or that they leave the page.

Hi flyblackbox - welcome to DaniWeb. I am not sure if Analytics can track a sale all the way through PayPal (my guess is that it doesn't). However, when the user finalizes Payment through paypal, you can redirect them to a unique "thank you" page that is hosted on your site - which will connect and finalize the sales process. Just be sure to add the analytics code to your thank you page.

Yeah I have that set up, but the problem is that after a sale, you have to click the 'finalize sale' link from the Paypal page.

It is not mandatory to click that link however, and many users simply close the window. You know what I mean?

Hmm.. can you not make it mandatory within PayPal? I could have sworn there was/is a way to automatically redirect users back to your site upon final sale.

I thought I had this setting turned on.

I found an article that describes this on Google:

https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-website-payments
http://screencast.com/t/YjgwYTNkYWUt

BUT, then I read this:

Customers can check out without a PayPal account

When the "account optional" feature is turned on, customers don't need a PayPal account. They use an alternate checkout and have the option to sign up for a PayPal account afterward. Customers with PayPal accounts still log in to their PayPal accounts to check out.

This feature is available for Buy Now buttons, Donations, and shopping carts.

Please note that if both the "auto return" and "account optional" features are turned on, customers who don't log in to PayPal can choose to go back to your website after checkout, but aren’t returned automatically.

So if a customer doesn't use paypal to pay for the item, the auto-return feature will not work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.