Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Add Revenue Tracking #25

Open
BFTrick opened this issue Sep 29, 2016 · 1 comment
Open

Add Revenue Tracking #25

BFTrick opened this issue Sep 29, 2016 · 1 comment

Comments

@BFTrick
Copy link

BFTrick commented Sep 29, 2016

This plugin could automatically add revenue tracking for some of the largest WordPress e-commerce plugins like WooCommerce & Easy Digital Downloads.

It's a small amount of code and could make revenue tracking so much easier. Here's a snippet how one website set's it up.

function eddwp_optimizely_revenue_tracking() {
    if( ! function_exists( 'edd_get_purchase_session' ) ) {
        return;
    }
    if( function_exists( 'edd_is_success_page' ) && ! edd_is_success_page() ) {
        return;
    }
    $session = edd_get_purchase_session();
    if( ! $session ) {
        return;
    }
    $payment_id = edd_get_purchase_id_by_key( $session['purchase_key'] );
?>
<script>
    var price = <?php echo edd_get_payment_amount( $payment_id ); ?>;
    window.optimizely = window.optimizely || [];
    window.optimizely.push(['trackEvent', 'purchase_complete', {'revenue': price * 100}]);
</script>
<?php
}
add_action( 'wp_head', 'eddwp_optimizely_revenue_tracking', 11 );

From: https://github.com/easydigitaldownloads/edd-custom-functions/blob/master/custom-functions.php#L150-L173

@circleddie
Copy link

@BFTrick Going to test this on my end with the plugin and confirm if it causes any issues down the road or not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants