Mautic server side tracking?

What I’d like to do…



Set up a Mautic server side tracking script, use it to send a virtual ‘payment complete’ pageview to Mautic. When this virtual pageview occurs, it updates the contacts ‘Stage’ to ‘Paid’ using a campaign.



Some background to my set up…



I have a site which sells products via Paypal. To track sales in analytics I do not use thank you page javascipt as it’s unreliable (about 20% of Paypal users don’t get returned), which leads to inaccurate tracking. Instead I have a server side php IPN listener script which tracks sales, the IPN url (along with a parameter of the users google analytics client id) is posted to paypal at checkout, then when the user pays, Paypal sends the script payment confirmation. At this point the script does two things, first it updates my orders payment database table with the customers payment status, it then uses a google server side analytics script which sends a virtual ‘payment complete’ page url directly to googles anaytics servers via payload. Importantly this is all done server side and not client side, i.e. google analytics tracking pixels are not and cannot be used.



This is what the server side google analytics code looks like…

Code:
$googleuid = $_POST['clientid']; $data = array('v' => '1', 'tid' => 'ANALYTICS ID', 'cid' => $googleuid, 't' => 'pageview', 'dt' => 'Paypal', 'dp' => 'paypal-payment-complete'); $getString = 'https://www.google-analytics.com/collect?'; $getString .= http_build_query($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $getString); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); $info = curl_getinfo($ch);

At one time, I used a remarketing platform called cloudIQ. In order to track sales for this platform, within the same IPN listerner script I cloned the google analytics server side analytics code above and repurpose it for cloud IQ's tracking using the customers email as a unique identifier...
Code:
$email = $dataResult["Email"]; $dataiqcloud = array('mode' => 'confirmPurchase', 'appId' => 'Cloud IQ ID', 'email' => $email); $getStringiqcloud = 'http://platform.cloud-iq.com/cartrecovery/?'; $getStringiqcloud .= http_build_query($dataiqcloud); $chiqcloud = curl_init(); curl_setopt($chiqcloud, CURLOPT_URL, $getStringiqcloud); curl_setopt($chiqcloud, CURLOPT_HEADER, 0); curl_exec($chiqcloud); $infoiqcloud = curl_getinfo($chiqcloud); curl_close($ciqcloudh); curl_close($ch);

I created a campaign form in mautic which takes the same fields as my current checkout (First Name, Last Name, Email, Address Details). I then took the mautic action url and form field names from the subsequent form and implemented a ajax / php curl script which onsubmit posts my form data to mautic, before posting my usual form to paypal. This works fine. It creates a contact in mautic and posts checkout info to Paypal after. However once the user pays and paypal sends payment complete status to my IPN script, I want a virual 'payment complete' pageview to be sent to Mautic, so I can use a campaign to update the contacts 'Stage' to 'Paid'.

So my questions are...

Can I use an amended version of the above script to track a virtual 'payment complete' pageview in mautic? If so, what would that look like?

If this is not possible, what are alternative options to achieve the same end result (i.e. update the contacts stage to 'Paid' without relying on client side thank you page php / js pixel tracking?


What I’d like to do…

Set up a Mautic server side tracking script, use it to send a virtual ‘payment complete’ pageview to Mautic. When this virtual pageview occurs, it updates the contacts ‘Stage’ to ‘Paid’ using a campaign.

Some background to my set up…

I have a site which sells products via Paypal. To track sales in analytics I do not use thank you page javascipt as it’s unreliable (about 20% of Paypal users don’t get returned), which leads to inaccurate tracking. Instead I have a server side php IPN listener script which tracks sales, the IPN url (along with a parameter of the users google analytics client id) is posted to paypal at checkout, then when the user pays, Paypal sends the script payment confirmation. At this point the script does two things, first it updates my orders payment database table with the customers payment status, it then uses a google server side analytics script which sends a virtual ‘payment complete’ page url directly to googles anaytics servers via payload. Importantly this is all done server side and not client side, i.e. google analytics tracking pixels are not and cannot be used.

This is what the server side google analytics code looks like…

$googleuid = $_POST['clientid']; $data = array('v' => '1', 'tid' => 'ANALYTICS ID', 'cid' => $googleuid, 't' => 'pageview', 'dt' => 'Paypal', 'dp' => 'paypal-payment-complete'); $getString = 'https://www.google-analytics.com/collect?'; $getString .= http_build_query($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $getString); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); $info = curl_getinfo($ch);

At one time, I used a remarketing platform called cloudIQ. In order to track sales for this platform, within the same IPN listerner script I cloned the google analytics server side analytics code above and repurpose it for cloud IQ’s tracking using the customers email as a unique identifier…

$email = $dataResult["Email"]; $dataiqcloud = array('mode' => 'confirmPurchase', 'appId' => 'Cloud IQ ID', 'email' => $email); $getStringiqcloud = 'http://platform.cloud-iq.com/cartrecovery/?'; $getStringiqcloud .= http_build_query($dataiqcloud); $chiqcloud = curl_init(); curl_setopt($chiqcloud, CURLOPT_URL, $getStringiqcloud); curl_setopt($chiqcloud, CURLOPT_HEADER, 0); curl_exec($chiqcloud); $infoiqcloud = curl_getinfo($chiqcloud); curl_close($ciqcloudh); curl_close($ch);

I created a campaign form in mautic which takes the same fields as my current checkout (First Name, Last Name, Email, Address Details). I then took the mautic action url and form field names from the subsequent form and implemented a ajax / php curl script which onsubmit posts my form data to mautic, before posting my usual form to paypal. This works fine. It creates a contact in mautic and posts checkout info to Paypal after. However once the user pays and paypal sends payment complete status to my IPN script, I want a virual ‘payment complete’ pageview to be sent to Mautic, so I can use a campaign to update the contacts ‘Stage’ to ‘Paid’.

So my questions are…

Can I use an amended version of the above script to track a virtual ‘payment complete’ pageview in mautic? If so, what would that look like?

If this is not possible, what are alternative options to achieve the same end result (i.e. update the contacts stage to ‘Paid’ without relying on client side thank you page php / js pixel tracking?

Is it sufficient for the user to simply visit an arbitrary page? If so, you could make a landing page in Mautic like:

www.SampleMauticSite.com/MyConfirmationLandingPage

And then CURL that or use a tracking pixel to hit it (I recommend the pixel because you’ll have to supply some info server side to ID the exact customer).

Is that along the lines of what you’re trying to achieve, or do you need to report on this differently? Where will the data ultimately be used/surfaced up to?

Hi, thanks so much for your reply!

Issue with confirmation page tracking and Paypal standard checkout

The main issue with using a confirmation landing page for sales tracking is related to how Paypal handles redirection to a sites confirmation page after the user has paid. If a user has a Paypal account - logins in - pays - the user is automatically redirected from paypal back to the websites confirmation page and the sale is tracked (albeit after a delay of a few seconds) … in this instance some users click away from Paypal and not redirected however. But worse, if a users pays through a guest account, paypal does not automatically redirect the user to a sites confirmation page after a sale, and instead remains on paypal.com and encourages the user to register their account, they do offer a link to return to the vendors confirmation page, but this often doesn’t get clicked. This all ended with roughly 20% of sales not being tracked. The way I got round this for tracking sales in analytics and the remarketing platform cloudiq was by sever side tracking in a IPN listener script. This script is never accessed by the client, instead it received payment confirmation data directly from Paypal at actual point of sale, meaning fully accurate sales tracking. The way server side analytics works is rather than use a pixel as a unique identifier, I first grab the analytics client id and store it in a cookie, then when the user post from my websites checkout customer details form to paypal, that includes my ipn url with a parameter on the end of the url with the clients analytics client id. I’m assuming mautic has some kind of similar session id I could use for tracking? When the user pays, the ipn script is sent the payment status from paypal and then sends a ‘virtual’ pageview along with the client analytics id to googles analytics servers via payload.

How the sales tracking will be used with Mautic

I plan to use Mautic for email and social remarketing. I would like to capture user details on my websites checkout customer details page before they are sent to paypal to pay. Once they have paid, I would like to track that payment at point of sale using the IPN script mentioned above rather then track the sale using a confirmation page, for fully reliable accurate sales tracking. Initially the most basic thing I want to set up upfront is a campaign to do the following…

  • Get contacts info from my websites checkout form
  • On condition met ‘Sale tracked’ - Update contacts stage to Paid and send out confirmation email of purchase
  • On condition NOT met ‘Sale tracked’ after 24 hours - Update contacts stage to Not Paid, send out cart abandonment remarketing email, with possible follows with increasingly persuasive offers if sale is still not completed.
  • On condition met ‘Contacts stage updated to ‘Paid’ 5 days previous’, send out invite to review service on Trustpilot.

Just that basic campaign will save a fortune in monthly premium third party services from trustpilot and cloudiq!

I did some research on the mautic forum. I did find this post relating to the mautic API library…
https://www.mautic.org/community/index.php/82-how-can-i-use-the-mautic-api/0#p265

I think there might be potential with the API to achieve what I need. Am I correct in assuming that? Following this url…
https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api/
I got as far as step 3 … adding the API ‘Lib’ folder to my mautic install, in the settings I switched on the API and got the API credentials, copied the script at step 3 and filled in the api details. Then stumbled at step 4… making api calls for what I want to do. I’m not really an expert in this stuff. Is it possible to do what I am describing using the API library? If so any idea what code I need to use in order to do it?

The other option I looked at was using Zapier which I read somewhere can communicate paypal sales with mautic. Is that possible / a better option?

Still haven’t made any meaningful progress on this. Does anyone know a decent solution? Any help appreciated!

1 Like