Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Freemius Purchase Completion JavaScript Callback Filter
<?php
function my_after_purchase_js( $js_function ) {
return 'function (data) {
console.log("checkout", "purchaseCompleted");
}';
}
my_freemius()->add_filter('checkout/purchaseCompleted', 'my_after_purchase_js');
?>
@irfan-blackandwhite

This comment has been minimized.

Copy link

@irfan-blackandwhite irfan-blackandwhite commented Feb 26, 2020

Hi,
would you elaborate where does this code goes. shell i add this code to the plugin header where Facebook pixel code already added or somewhere else?
Many thanks
irfan Qasim

@FQ400

This comment has been minimized.

Copy link

@FQ400 FQ400 commented Jun 19, 2020

There is a bug in my_freemius()->add_filter('checkout/purchaseCompleted', ''my_after_purchase_js);

It should be my_freemius()->add_filter('checkout/purchaseCompleted', 'my_after_purchase_js');

@FQ400

This comment has been minimized.

Copy link

@FQ400 FQ400 commented Jun 19, 2020

@irfan-blackandwhite put it in a PHP file that is included after your freemius code is initialized.

@daigo75

This comment has been minimized.

Copy link

@daigo75 daigo75 commented Feb 1, 2021

How does this code tie with the tracking of purchases with Google Analytics? I can see that the purpose is to return a JS function that will act as callback. The callback receives a data object, but it's unclear of what that object contains, and how it can be used to track the purchase. A more detailed example would be useful. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment