Last active
March 3, 2017 05:21
-
-
Save MikeCraig418/1163ff9092597cc9672791adcfe6c40e to your computer and use it in GitHub Desktop.
WooCommerce Conditional Goal Tracking
This file contains hidden or 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
<?php | |
function custom_tracking( $order_id ) { | |
if ($_COOKIE['source'] == 'social') : ?> | |
<script> | |
/* tracking code goes here */ | |
console.log('triggered'); | |
</script> | |
<?php | |
endif; | |
} | |
add_action( 'woocommerce_thankyou', 'custom_tracking' ); | |
?> |
This file contains hidden or 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
<?php | |
if (isset($_GET['source']) || $_GET['source'] == 'social') : | |
setcookie( 'source', 'social', 365 * 60*60*24 ); // 365 days | |
endif; | |
?> |
This file contains hidden or 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
A WordPress code snippet to track conversions via a set cookie. | |
Trigger on: | |
http://sitename.com/?source=social |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment