Last active
December 28, 2023 02:15
-
-
Save alexminza/c5b40a009b88a5100785e3b2aa981dd2 to your computer and use it in GitHub Desktop.
WooCommerce Google Analytics Integration - add UserID tracking
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
<?php | |
//https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/master/includes/class-wc-google-analytics-js.php | |
function woocommerce_ga_snippet_output_userid($code) { | |
$user_id = get_current_user_id(); | |
if($user_id > 0) { | |
$ga_user_id = WC_Google_Analytics_JS::tracker_var() . "('set', 'userId', '" . $user_id . "');"; | |
$code = $code . $ga_user_id; | |
} | |
return $code; | |
} | |
add_filter('woocommerce_ga_snippet_output', 'woocommerce_ga_snippet_output_userid'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment