Revenue/conversion tracking on Facebook & Google Analytics Answered
I had been trying to figure out revenue/conversion tracking on Facebook & Google Analytics for a while, and have now got it working.
If you use a “thank you” page after checkout complete and you want to send a revenue number to Facebook Ads or Google Analytics, here is a script that you can add to your page.
It still has a few caveats - if anyone would like to help improve it, please feel free!
- doesn’t factor in discounts/trials
- my script uses EUR - change this for your currency
- I’m pretty sure it will double count if a user refreshes the thank you page
- Note, you need the GA4 tag set up on your website
Hope this is useful to someone - it would have been useful to me 🙂
<script>
const memberstack = window.$memberstackDom;
memberstack.getCurrentMember().then(({ data: member }) => {
const planConnections = member.planConnections;
// Check if there are any plan connections
if (planConnections && planConnections.length > 0) {
const lastPlanConnection = planConnections[planConnections.length - 1];
const fbAmount = lastPlanConnection.payment.amount;
console.log(fbAmount);
fbq('track', 'Purchase', { currency: 'EUR', value: fbAmount });
gtag("event", "purchase", {
value: fbAmount,
currency: "EUR",
items: [
{
item_id: lastPlanConnection.planId,
price: fbAmount,
quantity: 1
}]
});
}
});
</script>
Comments
5 comments
Alastair Budge Nice, thx!
So does it only fire if the member actually has at least 1 paid plan? Or can it also fire if the member hasn't paid yet
I ask this as I noticed that sometimes my users get redirected to the succesful payment page after leaving the Stripe checkout without converting
Hmm, it will only fire if they have a plan.
Users shouldn’t be redirected to a thank-you page without a successful checkout…
I know, seemed like a bug
But that's cool. I will try and change the snippet so it checks if the browser session has a specific cookie set and only fire the event if it doesn't. Then set the cookie after that event so the event can only fire once per browser session.
Will share it later on if you want 🙂
Great! Thanks for the amazing tips Alastair Budge. But how do you redirect members to a specific page after purchase?
Aurélien Gallier undefined this comes “out of the box” with Memberstack: https://docs.memberstack.com/hc/en-us/articles/7384608370715-Default-Redirects-Plan-Redirects-Signup-Login-Logout-
Please sign in to leave a comment.