I have a simple flow with a Paypal button:

enter image description here

   Website example.com        ===> Paypal interface ===>   Payment success page 
[simple Paypal BUY button]                                 example.com/success
[     without cart       ]

I would like to track conversions with Google Analytics and Facebook ads manager.

In order to do that, I have set a "Goal" in Google Analytics: When example.com/success is visited, it is a purchase. The same can be done with Facebook ads (see screenshot below).


  • sometimes, after Paypal processes a payment, the customer doesn't go back to example.com/success. Then the conversion cannot be tracked.

  • if someone visits the success page from multiple devices, it can be tracked as multiple conversions, which is a mistake!


How to detect conversions in a configuration with a simple Paypal Buy button?


Note: Here is how looks the conversion setup in Facebook:

enter image description here

  • Have you specified a checkout redirect URL in Paypal for successful/cancelled purchases?
    – L Martin
    Jun 26, 2017 at 14:43
  • Yes @Yhorian I have set example.com\success as redirect URL after a successful purchase in Paypal's BUY button settings. But some users (<30%) don't necessarily wait for the redirection before closing the Paypal tab of browser. Then example.com\success is not shown. Then the FB pixel doesn't track this, then the conversion is not tracked. Do you have an idea?
    – Basj
    Jun 26, 2017 at 19:15
  • It may not fit an answer as it's untested but have you considered a tracking event based on a javascript call-back? So Paypal opens in a new window and a websocket contacts the client in the original window to trigger the event when payment is confirmed with your server.
    – L Martin
    Jun 27, 2017 at 10:01

1 Answer 1


I finally found a solution. It works with Google Analytics, I haven't found for Facebook yet.

  1. On your website, inside the Paypal button code <form>...</form>, add a field <input type="hidden" name="custom" value="(userid)"> where the userid is set with Javascript, taken from Google Analytics cookie, such as document.cookie's _ga.

  2. This custom field will be passed to Paypal when the user clicks "BUY", and will be passed to IPN PHP code that runs after each successful payement. It can be retrieved in the IPN PHP code with $_POST['custom'].

  3. In the Paypal IPN PHP code, you can send a request to GoogleAnalytics to manually trigger a pageview of a virtual page named example.com\thisisapurchase. Something like this works:

    $data = array('v' => 1, 'tid' => 'UA-xxxxxxx-x', 'cid' => $_POST['custom'], 't' => 'pageview', 'dh' => 'www.example.com', 'dp' => 'thisisapurchase', 'dt' => 'thisisapurchase');
    $options = array('http' => array('method' => 'POST', 'content' => http_build_query($data)));
    $context = stream_context_create($options);
    $result = file_get_contents('https://www.google-analytics.com/collect', false, $context);
  4. In Google Analytics, create a "Goal" with destination = example.com\thisisapurchase

Then the visitor who visited the website, and who did a purchase (he visited a virtual page named example.com\thisisapurchase) will be seen as one unique visitor in Google Analytics.

Then you can reliably know from which source he comes from (referral, affiliate, etc.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.