Skip to content

Instantly share code, notes, and snippets.

@maucherOnline
Last active March 1, 2023 12:44
Show Gist options
  • Save maucherOnline/7b07c989fed5816b46a2d7d0f7b1a266 to your computer and use it in GitHub Desktop.
Save maucherOnline/7b07c989fed5816b46a2d7d0f7b1a266 to your computer and use it in GitHub Desktop.
Include Google Analytics tracking in freemius checkout
<script src="https://checkout.freemius.com/checkout.min.js"></script>
<script>
var handler = FS.Checkout.configure({
plugin_id: 'xxxxx',
plan_id: 'xxxxx',
public_key: 'pk_yyyyyyyyyyyyyyyyyy',
image: 'https://yyy.com/Logo-SVG.svg'
});
jQuery('.purchase, a[href*="#purchase"').on('click', function (e) {
handler.open({
name : 'My awesome Plugin',
licenses : 1,
// You can consume the response for after purchase logic.
purchaseCompleted : function (response) {
// The logic here will be executed immediately after the purchase confirmation. // alert(response.user.email);
},
success : function (response) {
// The logic here will be executed after the customer closes the checkout, after a successful purchase. // alert(response.user.email);
},
purchaseCompleted: function( response ) {
if ( typeof gtag !== undefined ) {
gtag('event', 'purchase', {
'value': response.purchase.initial_amount,
'currency': 'USD'
});
}
}
});
e.preventDefault();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment