Skip to content

Instantly share code, notes, and snippets.

@MikeCraig418
Last active March 3, 2017 05:21
Show Gist options
  • Save MikeCraig418/1163ff9092597cc9672791adcfe6c40e to your computer and use it in GitHub Desktop.
Save MikeCraig418/1163ff9092597cc9672791adcfe6c40e to your computer and use it in GitHub Desktop.
WooCommerce Conditional Goal Tracking
<?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' );
?>
<?php
if (isset($_GET['source']) || $_GET['source'] == 'social') :
setcookie( 'source', 'social', 365 * 60*60*24 ); // 365 days
endif;
?>
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