Last active
March 1, 2023 12:44
-
-
Save maucherOnline/7b07c989fed5816b46a2d7d0f7b1a266 to your computer and use it in GitHub Desktop.
Include Google Analytics tracking in freemius checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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