Created
May 16, 2016 20:16
-
-
Save digitalchild/f05852d925c8f00fa83aaace210dbee3 to your computer and use it in GitHub Desktop.
Google Analytics Code for Vendors
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 | |
// Place this code in your themes functions.php | |
// Add google analytics code to vendor pages for tracking | |
function wcv_shop_name_google_analytics() { | |
if ( is_singular( 'product') ){ | |
$product = get_queried_object(); | |
if ( WCV_Vendors::is_vendor_product_page( $product->post_author ) ) { | |
$vendor_id = $product->post_author; | |
} | |
} | |
if ( WCV_Vendors::is_vendor_page() ) { | |
$vendor_shop = urldecode( get_query_var( 'vendor_shop' ) ); | |
$vendor_id = WCV_Vendors::get_vendor_id( $vendor_shop ); | |
} | |
$vendor_shop_name = get_user_meta( $vendor_id, 'pv_shop_name', true ); | |
echo " | |
<script> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'Analytics Property ID Goes Here', 'auto'); | |
ga('set', 'dimension1', '".$vendor_shop_name."'); | |
ga('send', 'pageview'); | |
</script>"; | |
} // wcv_shop_name_google_analytics() | |
add_action ('wp_head', 'wcv_shop_name_google_analytics'); |
- What does it track?
This code is outdated and should not be used. Please see our documentation on how to do this now.
https://docs.wcvendors.com/knowledge-base/allow-vendors-to-add-google-analytics-tracking-code/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this still working without an issue?