Revenue/conversion tracking on Facebook & Google Analytics Answered

Post author
Alastair Budge

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

Please sign in to leave a comment.