Version Description
01/05/2017 =
Add - Filters for GA snippet (woocommerce_ga_snippet_head, woocommerce_ga_snippet_create, woocommerce_ga_snippet_require, woocommerce_ga_snippet_output)
Add - Option to toggle on/off Enhanced Link Attribution
Fix - JavaScript break by wrapping it in quotes
Fix - Use ID and SKU data in a consistent way so that all products are correctly tracked.
Fix - Updates for WooCommerce 3.0 compatibility.
Add - Settings link to the plugin in the Plugins screen
Fix - Fatal error on shortcode usage for empty product
Download this release
Release Info
| Developer | bor0 |
| Plugin | |
| Version | 1.4.1 |
| Comparing to | |
| See all releases | |
Code changes from version 1.4.0 to 1.4.1
- README.md +0 -5
- includes/class-wc-google-analytics-js.php +49 -29
- includes/class-wc-google-analytics.php +21 -11
- package.json +1 -1
- readme.txt +19 -3
- woocommerce-google-analytics-integration.php +23 -4
README.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
# WooCommerce Google Analytics Integration
|
| 2 |
-
|
| 3 |
-
WordPress plugin: Provides the integration between WooCommerce and Google Analytics.
|
| 4 |
-
|
| 5 |
-
Will be required for WooCommerce shops using the integration from WooCommerce 2.1 and up.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/class-wc-google-analytics-js.php
CHANGED
|
@@ -91,9 +91,9 @@ class WC_Google_Analytics_JS {
|
|
| 91 |
if ( 'yes' === self::get( 'ga_anonymize_enabled' ) ) {
|
| 92 |
$anonymize_enabled = "['_gat._anonymizeIp'],";
|
| 93 |
}
|
| 94 |
-
|
| 95 |
$domainname = self::get( 'ga_set_domain_name' );
|
| 96 |
-
|
| 97 |
if ( ! empty( $domainname ) ) {
|
| 98 |
$set_domain_name = "['_setDomainName', '" . esc_js( self::get( 'ga_set_domain_name' ) ) . "'],";
|
| 99 |
} else {
|
|
@@ -108,7 +108,7 @@ class WC_Google_Analytics_JS {
|
|
| 108 |
['_trackPageview']";
|
| 109 |
|
| 110 |
if ( false !== $order ) {
|
| 111 |
-
$code .= ",['_set', 'currencyCode', '" . esc_js( $order->get_order_currency() ) . "']";
|
| 112 |
}
|
| 113 |
|
| 114 |
$code .= ");";
|
|
@@ -128,11 +128,11 @@ class WC_Google_Analytics_JS {
|
|
| 128 |
|
| 129 |
wc_enqueue_js( "
|
| 130 |
" . self::tracker_var() . "( 'ec:addImpression', {
|
| 131 |
-
'id': '" . esc_js( $product->
|
| 132 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 133 |
'category': " . self::product_get_category_line( $product ) . "
|
| 134 |
'list': '" . esc_js( $list ) . "',
|
| 135 |
-
'position': " . esc_js( $position ) . "
|
| 136 |
} );
|
| 137 |
" );
|
| 138 |
}
|
|
@@ -150,16 +150,16 @@ class WC_Google_Analytics_JS {
|
|
| 150 |
echo( "
|
| 151 |
<script>
|
| 152 |
(function($) {
|
| 153 |
-
$( '.products .post-" . esc_js( $product->
|
| 154 |
if ( true === $(this).hasClass( 'add_to_cart_button' ) ) {
|
| 155 |
return;
|
| 156 |
}
|
| 157 |
|
| 158 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 159 |
-
'id': '" . esc_js( $product->
|
| 160 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 161 |
'category': " . self::product_get_category_line( $product ) . "
|
| 162 |
-
'position': " . esc_js( $position ) . "
|
| 163 |
});
|
| 164 |
|
| 165 |
" . self::tracker_var() . "( 'ec:setAction', 'click', { list: '" . esc_js( $list ) . "' });
|
|
@@ -202,9 +202,9 @@ class WC_Google_Analytics_JS {
|
|
| 202 |
* @return string Universal Analytics Code
|
| 203 |
*/
|
| 204 |
public static function load_analytics_universal( $logged_in ) {
|
| 205 |
-
|
| 206 |
$domainname = self::get( 'ga_set_domain_name' );
|
| 207 |
-
|
| 208 |
if ( ! empty( $domainname ) ) {
|
| 209 |
$set_domain_name = esc_js( self::get( 'ga_set_domain_name' ) );
|
| 210 |
} else {
|
|
@@ -216,27 +216,42 @@ class WC_Google_Analytics_JS {
|
|
| 216 |
$support_display_advertising = "" . self::tracker_var() . "( 'require', 'displayfeatures' );";
|
| 217 |
}
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
$anonymize_enabled = '';
|
| 220 |
if ( 'yes' === self::get( 'ga_anonymize_enabled' ) ) {
|
| 221 |
$anonymize_enabled = "" . self::tracker_var() . "( 'set', 'anonymizeIp', true );";
|
| 222 |
}
|
| 223 |
|
| 224 |
-
$
|
| 225 |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
| 226 |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
| 227 |
-
})(window,document,'script','//www.google-analytics.com/analytics.js','" . self::tracker_var() . "');
|
| 228 |
|
| 229 |
-
|
|
|
|
|
|
|
| 230 |
$support_display_advertising .
|
|
|
|
| 231 |
$anonymize_enabled . "
|
| 232 |
" . self::tracker_var() . "( 'set', 'dimension1', '" . $logged_in . "' );\n";
|
| 233 |
|
| 234 |
if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) ) {
|
| 235 |
-
$
|
| 236 |
} else {
|
| 237 |
-
$
|
| 238 |
}
|
| 239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
return $code;
|
| 241 |
}
|
| 242 |
|
|
@@ -269,9 +284,9 @@ class WC_Google_Analytics_JS {
|
|
| 269 |
'" . esc_js( $order->get_total() ) . "', // total - required
|
| 270 |
'" . esc_js( $order->get_total_tax() ) . "', // tax
|
| 271 |
'" . esc_js( $order->get_total_shipping() ) . "', // shipping
|
| 272 |
-
'" . esc_js( $order->billing_city ) . "', // city
|
| 273 |
-
'" . esc_js( $order->billing_state ) . "', // state or province
|
| 274 |
-
'" . esc_js( $order->billing_country ) . "' // country
|
| 275 |
]);";
|
| 276 |
|
| 277 |
// Order items
|
|
@@ -297,7 +312,7 @@ class WC_Google_Analytics_JS {
|
|
| 297 |
'revenue': '" . esc_js( $order->get_total() ) . "', // Grand Total
|
| 298 |
'shipping': '" . esc_js( $order->get_total_shipping() ) . "', // Shipping
|
| 299 |
'tax': '" . esc_js( $order->get_total_tax() ) . "', // Tax
|
| 300 |
-
'currency': '" . esc_js( $order->get_order_currency() ) . "' // Currency
|
| 301 |
});";
|
| 302 |
|
| 303 |
// Order items
|
|
@@ -315,7 +330,7 @@ class WC_Google_Analytics_JS {
|
|
| 315 |
* Enhanced Ecommerce Universal Analytics transaction tracking
|
| 316 |
*/
|
| 317 |
function add_transaction_enhanced( $order ) {
|
| 318 |
-
$code = "" . self::tracker_var() . "( 'set', '&cu', '" . esc_js( $order->get_order_currency() ) . "' );";
|
| 319 |
|
| 320 |
// Order items
|
| 321 |
if ( $order->get_items() ) {
|
|
@@ -345,7 +360,7 @@ class WC_Google_Analytics_JS {
|
|
| 345 |
|
| 346 |
$code = "_gaq.push(['_addItem',";
|
| 347 |
$code .= "'" . esc_js( $order->get_order_number() ) . "',";
|
| 348 |
-
$code .= "'" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->
|
| 349 |
$code .= "'" . esc_js( $item['name'] ) . "',";
|
| 350 |
$code .= self::product_get_category_line( $_product );
|
| 351 |
$code .= "'" . esc_js( $order->get_item_total( $item ) ) . "',";
|
|
@@ -366,7 +381,7 @@ class WC_Google_Analytics_JS {
|
|
| 366 |
$code = "" . self::tracker_var() . "('ecommerce:addItem', {";
|
| 367 |
$code .= "'id': '" . esc_js( $order->get_order_number() ) . "',";
|
| 368 |
$code .= "'name': '" . esc_js( $item['name'] ) . "',";
|
| 369 |
-
$code .= "'sku': '" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->
|
| 370 |
$code .= "'category': " . self::product_get_category_line( $_product );
|
| 371 |
$code .= "'price': '" . esc_js( $order->get_item_total( $item ) ) . "',";
|
| 372 |
$code .= "'quantity': '" . esc_js( $item['qty'] ) . "'";
|
|
@@ -384,7 +399,7 @@ class WC_Google_Analytics_JS {
|
|
| 384 |
$_product = $order->get_product_from_item( $item );
|
| 385 |
|
| 386 |
$code = "" . self::tracker_var() . "( 'ec:addProduct', {";
|
| 387 |
-
$code .= "'id': '" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->
|
| 388 |
$code .= "'name': '" . esc_js( $item['name'] ) . "',";
|
| 389 |
$code .= "'category': " . self::product_get_category_line( $_product );
|
| 390 |
$code .= "'price': '" . esc_js( $order->get_item_total( $item ) ) . "',";
|
|
@@ -400,11 +415,12 @@ class WC_Google_Analytics_JS {
|
|
| 400 |
* @return string Line of JSON
|
| 401 |
*/
|
| 402 |
private static function product_get_category_line( $_product ) {
|
| 403 |
-
|
| 404 |
-
|
|
|
|
| 405 |
} else {
|
| 406 |
$out = array();
|
| 407 |
-
$categories = get_the_terms( $_product->
|
| 408 |
if ( $categories ) {
|
| 409 |
foreach ( $categories as $category ) {
|
| 410 |
$out[] = $category->name;
|
|
@@ -425,7 +441,7 @@ class WC_Google_Analytics_JS {
|
|
| 425 |
(function($) {
|
| 426 |
$( '.remove' ).click( function() {
|
| 427 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 428 |
-
'id': ($(this).data('product_sku')) ? (
|
| 429 |
'quantity': $(this).parent().parent().find( '.qty' ).val() ? $(this).parent().parent().find( '.qty' ).val() : '1',
|
| 430 |
} );
|
| 431 |
" . self::tracker_var() . "( 'ec:setAction', 'remove' );
|
|
@@ -440,9 +456,13 @@ class WC_Google_Analytics_JS {
|
|
| 440 |
* Tracks a product detail view
|
| 441 |
*/
|
| 442 |
function product_detail( $product ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
wc_enqueue_js( "
|
| 444 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 445 |
-
'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : $product->
|
| 446 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 447 |
'category': " . self::product_get_category_line( $product ) . "
|
| 448 |
'price': '" . esc_js( $product->get_price() ) . "',
|
|
@@ -460,7 +480,7 @@ class WC_Google_Analytics_JS {
|
|
| 460 |
foreach ( $cart as $cart_item_key => $cart_item ) {
|
| 461 |
$product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
|
| 462 |
$code .= "" . self::tracker_var() . "( 'ec:addProduct', {
|
| 463 |
-
'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : $product->
|
| 464 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 465 |
'category': " . self::product_get_category_line( $product ) . "
|
| 466 |
'price': '" . esc_js( $product->get_price() ) . "',
|
| 91 |
if ( 'yes' === self::get( 'ga_anonymize_enabled' ) ) {
|
| 92 |
$anonymize_enabled = "['_gat._anonymizeIp'],";
|
| 93 |
}
|
| 94 |
+
|
| 95 |
$domainname = self::get( 'ga_set_domain_name' );
|
| 96 |
+
|
| 97 |
if ( ! empty( $domainname ) ) {
|
| 98 |
$set_domain_name = "['_setDomainName', '" . esc_js( self::get( 'ga_set_domain_name' ) ) . "'],";
|
| 99 |
} else {
|
| 108 |
['_trackPageview']";
|
| 109 |
|
| 110 |
if ( false !== $order ) {
|
| 111 |
+
$code .= ",['_set', 'currencyCode', '" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ) . "']";
|
| 112 |
}
|
| 113 |
|
| 114 |
$code .= ");";
|
| 128 |
|
| 129 |
wc_enqueue_js( "
|
| 130 |
" . self::tracker_var() . "( 'ec:addImpression', {
|
| 131 |
+
'id': '" . esc_js( $product->get_id() ) . "',
|
| 132 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 133 |
'category': " . self::product_get_category_line( $product ) . "
|
| 134 |
'list': '" . esc_js( $list ) . "',
|
| 135 |
+
'position': '" . esc_js( $position ) . "'
|
| 136 |
} );
|
| 137 |
" );
|
| 138 |
}
|
| 150 |
echo( "
|
| 151 |
<script>
|
| 152 |
(function($) {
|
| 153 |
+
$( '.products .post-" . esc_js( $product->get_id() ) . " a' ).click( function() {
|
| 154 |
if ( true === $(this).hasClass( 'add_to_cart_button' ) ) {
|
| 155 |
return;
|
| 156 |
}
|
| 157 |
|
| 158 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 159 |
+
'id': '" . esc_js( $product->get_id() ) . "',
|
| 160 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 161 |
'category': " . self::product_get_category_line( $product ) . "
|
| 162 |
+
'position': '" . esc_js( $position ) . "'
|
| 163 |
});
|
| 164 |
|
| 165 |
" . self::tracker_var() . "( 'ec:setAction', 'click', { list: '" . esc_js( $list ) . "' });
|
| 202 |
* @return string Universal Analytics Code
|
| 203 |
*/
|
| 204 |
public static function load_analytics_universal( $logged_in ) {
|
| 205 |
+
|
| 206 |
$domainname = self::get( 'ga_set_domain_name' );
|
| 207 |
+
|
| 208 |
if ( ! empty( $domainname ) ) {
|
| 209 |
$set_domain_name = esc_js( self::get( 'ga_set_domain_name' ) );
|
| 210 |
} else {
|
| 216 |
$support_display_advertising = "" . self::tracker_var() . "( 'require', 'displayfeatures' );";
|
| 217 |
}
|
| 218 |
|
| 219 |
+
$support_enhanced_link_attribution = '';
|
| 220 |
+
if ( 'yes' === self::get( 'ga_support_enhanced_link_attribution' ) ) {
|
| 221 |
+
$support_enhanced_link_attribution = "" . self::tracker_var() . "( 'require', 'linkid' );";
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
$anonymize_enabled = '';
|
| 225 |
if ( 'yes' === self::get( 'ga_anonymize_enabled' ) ) {
|
| 226 |
$anonymize_enabled = "" . self::tracker_var() . "( 'set', 'anonymizeIp', true );";
|
| 227 |
}
|
| 228 |
|
| 229 |
+
$ga_snippet_head = "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
| 230 |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
| 231 |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
| 232 |
+
})(window,document,'script','//www.google-analytics.com/analytics.js','" . self::tracker_var() . "');";
|
| 233 |
|
| 234 |
+
$ga_snippet_create = self::tracker_var() . "( 'create', '" . esc_js( $ga_id ) . "', '" . $set_domain_name . "' );";
|
| 235 |
+
|
| 236 |
+
$ga_snippet_require =
|
| 237 |
$support_display_advertising .
|
| 238 |
+
$support_enhanced_link_attribution .
|
| 239 |
$anonymize_enabled . "
|
| 240 |
" . self::tracker_var() . "( 'set', 'dimension1', '" . $logged_in . "' );\n";
|
| 241 |
|
| 242 |
if ( 'yes' === self::get( 'ga_enhanced_ecommerce_tracking_enabled' ) ) {
|
| 243 |
+
$ga_snippet_require .= "" . self::tracker_var() . "( 'require', 'ec' );";
|
| 244 |
} else {
|
| 245 |
+
$ga_snippet_require .= "" . self::tracker_var() . "( 'require', 'ecommerce', 'ecommerce.js');";
|
| 246 |
}
|
| 247 |
|
| 248 |
+
$ga_snippet_head = apply_filters( 'woocommerce_ga_snippet_head' , $ga_snippet_head );
|
| 249 |
+
$ga_snippet_create = apply_filters( 'woocommerce_ga_snippet_create' , $ga_snippet_create, $ga_id );
|
| 250 |
+
$ga_snippet_require = apply_filters( 'woocommerce_ga_snippet_require' , $ga_snippet_require );
|
| 251 |
+
|
| 252 |
+
$code = $ga_snippet_head . $ga_snippet_create . $ga_snippet_require;
|
| 253 |
+
$code = apply_filters( 'woocommerce_ga_snippet_output', $code );
|
| 254 |
+
|
| 255 |
return $code;
|
| 256 |
}
|
| 257 |
|
| 284 |
'" . esc_js( $order->get_total() ) . "', // total - required
|
| 285 |
'" . esc_js( $order->get_total_tax() ) . "', // tax
|
| 286 |
'" . esc_js( $order->get_total_shipping() ) . "', // shipping
|
| 287 |
+
'" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->billing_city : $order->get_billing_city() ) . "', // city
|
| 288 |
+
'" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->billing_state : $order->get_billing_state() ) . "', // state or province
|
| 289 |
+
'" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->billing_country : $order->get_billing_country() ) . "' // country
|
| 290 |
]);";
|
| 291 |
|
| 292 |
// Order items
|
| 312 |
'revenue': '" . esc_js( $order->get_total() ) . "', // Grand Total
|
| 313 |
'shipping': '" . esc_js( $order->get_total_shipping() ) . "', // Shipping
|
| 314 |
'tax': '" . esc_js( $order->get_total_tax() ) . "', // Tax
|
| 315 |
+
'currency': '" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ) . "' // Currency
|
| 316 |
});";
|
| 317 |
|
| 318 |
// Order items
|
| 330 |
* Enhanced Ecommerce Universal Analytics transaction tracking
|
| 331 |
*/
|
| 332 |
function add_transaction_enhanced( $order ) {
|
| 333 |
+
$code = "" . self::tracker_var() . "( 'set', '&cu', '" . esc_js( version_compare( WC_VERSION, '3.0', '<' ) ? $order->get_order_currency() : $order->get_currency() ) . "' );";
|
| 334 |
|
| 335 |
// Order items
|
| 336 |
if ( $order->get_items() ) {
|
| 360 |
|
| 361 |
$code = "_gaq.push(['_addItem',";
|
| 362 |
$code .= "'" . esc_js( $order->get_order_number() ) . "',";
|
| 363 |
+
$code .= "'" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->get_id() ) . "',";
|
| 364 |
$code .= "'" . esc_js( $item['name'] ) . "',";
|
| 365 |
$code .= self::product_get_category_line( $_product );
|
| 366 |
$code .= "'" . esc_js( $order->get_item_total( $item ) ) . "',";
|
| 381 |
$code = "" . self::tracker_var() . "('ecommerce:addItem', {";
|
| 382 |
$code .= "'id': '" . esc_js( $order->get_order_number() ) . "',";
|
| 383 |
$code .= "'name': '" . esc_js( $item['name'] ) . "',";
|
| 384 |
+
$code .= "'sku': '" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->get_id() ) . "',";
|
| 385 |
$code .= "'category': " . self::product_get_category_line( $_product );
|
| 386 |
$code .= "'price': '" . esc_js( $order->get_item_total( $item ) ) . "',";
|
| 387 |
$code .= "'quantity': '" . esc_js( $item['qty'] ) . "'";
|
| 399 |
$_product = $order->get_product_from_item( $item );
|
| 400 |
|
| 401 |
$code = "" . self::tracker_var() . "( 'ec:addProduct', {";
|
| 402 |
+
$code .= "'id': '" . esc_js( $_product->get_sku() ? $_product->get_sku() : $_product->get_id() ) . "',";
|
| 403 |
$code .= "'name': '" . esc_js( $item['name'] ) . "',";
|
| 404 |
$code .= "'category': " . self::product_get_category_line( $_product );
|
| 405 |
$code .= "'price': '" . esc_js( $order->get_item_total( $item ) ) . "',";
|
| 415 |
* @return string Line of JSON
|
| 416 |
*/
|
| 417 |
private static function product_get_category_line( $_product ) {
|
| 418 |
+
$variation_data = version_compare( WC_VERSION, '3.0', '<' ) ? $_product->variation_data : ( $_product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $_product->get_id() ) : '' );
|
| 419 |
+
if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
|
| 420 |
+
$code = "'" . esc_js( wc_get_formatted_variation( $_product->variation_data, true ) ) . "',";
|
| 421 |
} else {
|
| 422 |
$out = array();
|
| 423 |
+
$categories = get_the_terms( $_product->get_id(), 'product_cat' );
|
| 424 |
if ( $categories ) {
|
| 425 |
foreach ( $categories as $category ) {
|
| 426 |
$out[] = $category->name;
|
| 441 |
(function($) {
|
| 442 |
$( '.remove' ).click( function() {
|
| 443 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 444 |
+
'id': ($(this).data('product_sku')) ? ($(this).data('product_sku')) : ('#' + $(this).data('product_id')),
|
| 445 |
'quantity': $(this).parent().parent().find( '.qty' ).val() ? $(this).parent().parent().find( '.qty' ).val() : '1',
|
| 446 |
} );
|
| 447 |
" . self::tracker_var() . "( 'ec:setAction', 'remove' );
|
| 456 |
* Tracks a product detail view
|
| 457 |
*/
|
| 458 |
function product_detail( $product ) {
|
| 459 |
+
if ( empty( $product ) ) {
|
| 460 |
+
return;
|
| 461 |
+
}
|
| 462 |
+
|
| 463 |
wc_enqueue_js( "
|
| 464 |
" . self::tracker_var() . "( 'ec:addProduct', {
|
| 465 |
+
'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : ( '#' . $product->get_id() ) ) . "',
|
| 466 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 467 |
'category': " . self::product_get_category_line( $product ) . "
|
| 468 |
'price': '" . esc_js( $product->get_price() ) . "',
|
| 480 |
foreach ( $cart as $cart_item_key => $cart_item ) {
|
| 481 |
$product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
|
| 482 |
$code .= "" . self::tracker_var() . "( 'ec:addProduct', {
|
| 483 |
+
'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : ( '#' . $product->get_id() ) ) . "',
|
| 484 |
'name': '" . esc_js( $product->get_title() ) . "',
|
| 485 |
'category': " . self::product_get_category_line( $product ) . "
|
| 486 |
'price': '" . esc_js( $product->get_price() ) . "',
|
includes/class-wc-google-analytics.php
CHANGED
|
@@ -73,6 +73,7 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 73 |
'ga_set_domain_name',
|
| 74 |
'ga_standard_tracking_enabled',
|
| 75 |
'ga_support_display_advertising',
|
|
|
|
| 76 |
'ga_use_universal_analytics',
|
| 77 |
'ga_anonymize_enabled',
|
| 78 |
'ga_ecommerce_tracking_enabled',
|
|
@@ -126,6 +127,13 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 126 |
'checkboxgroup' => '',
|
| 127 |
'default' => get_option( 'woocommerce_ga_support_display_advertising' ) ? get_option( 'woocommerce_ga_support_display_advertising' ) : 'no' // Backwards compat
|
| 128 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
'ga_use_universal_analytics' => array(
|
| 130 |
'label' => __( 'Enable Universal Analytics', 'woocommerce-google-analytics-integration' ),
|
| 131 |
'description' => sprintf( __( 'Uses Universal Analytics instead of Classic Google Analytics. If you have <strong>not</strong> previously used Google Analytics on this site, check this box. Otherwise, %sfollow step 1 of the Universal Analytics upgrade guide.%s Enabling this setting will take care of step 2. %sRead more about Universal Analytics%s. Universal Analytics must be enabled to enable enhanced eCommerce.', 'woocommerce-google-analytics-integration' ), '<a href="https://developers.google.com/analytics/devguides/collection/upgrade/guide" target="_blank">', '</a>', '<a href="https://support.google.com/analytics/answer/2790010?hl=en" target="_blank">', '</a>' ),
|
|
@@ -225,12 +233,13 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 225 |
*/
|
| 226 |
function track_options( $data ) {
|
| 227 |
$data['wc-google-analytics'] = array(
|
| 228 |
-
'standard_tracking_enabled'
|
| 229 |
-
'support_display_advertising'
|
| 230 |
-
'
|
| 231 |
-
'
|
| 232 |
-
'
|
| 233 |
-
'
|
|
|
|
| 234 |
);
|
| 235 |
return $data;
|
| 236 |
}
|
|
@@ -351,11 +360,12 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 351 |
$parameters = array();
|
| 352 |
$parameters['category'] = "'" . __( 'Products', 'woocommerce-google-analytics-integration' ) . "'";
|
| 353 |
$parameters['action'] = "'" . __( 'Add to Cart', 'woocommerce-google-analytics-integration' ) . "'";
|
| 354 |
-
$parameters['label'] = "'" . esc_js( $product->get_sku() ? __( '
|
| 355 |
|
| 356 |
if ( ! $this->disable_tracking( $this->ga_enhanced_ecommerce_tracking_enabled ) ) {
|
| 357 |
$code = "" . WC_Google_Analytics_JS::get_instance()->tracker_var() . "( 'ec:addProduct', {";
|
| 358 |
-
$code .= "'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : $product->
|
|
|
|
| 359 |
$code .= "'quantity': $( 'input.qty' ).val() ? $( 'input.qty' ).val() : '1'";
|
| 360 |
$code .= "} );";
|
| 361 |
$parameters['enhanced'] = $code;
|
|
@@ -393,7 +403,7 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 393 |
|
| 394 |
$item = WC()->cart->get_cart_item( $key );
|
| 395 |
$product = $item['data'];
|
| 396 |
-
$url = str_replace( 'href=', 'data-product_id="' . esc_attr( $product->
|
| 397 |
return $url;
|
| 398 |
}
|
| 399 |
|
|
@@ -411,11 +421,11 @@ class WC_Google_Analytics extends WC_Integration {
|
|
| 411 |
$parameters = array();
|
| 412 |
$parameters['category'] = "'" . __( 'Products', 'woocommerce-google-analytics-integration' ) . "'";
|
| 413 |
$parameters['action'] = "'" . __( 'Add to Cart', 'woocommerce-google-analytics-integration' ) . "'";
|
| 414 |
-
$parameters['label'] = "($(this).data('product_sku')) ? (
|
| 415 |
|
| 416 |
if ( ! $this->disable_tracking( $this->ga_enhanced_ecommerce_tracking_enabled ) ) {
|
| 417 |
$code = "" . WC_Google_Analytics_JS::get_instance()->tracker_var() . "( 'ec:addProduct', {";
|
| 418 |
-
$code .= "'id': ($(this).data('product_sku')) ? (
|
| 419 |
$code .= "'quantity': $(this).data('quantity')";
|
| 420 |
$code .= "} );";
|
| 421 |
$parameters['enhanced'] = $code;
|
| 73 |
'ga_set_domain_name',
|
| 74 |
'ga_standard_tracking_enabled',
|
| 75 |
'ga_support_display_advertising',
|
| 76 |
+
'ga_support_enhanced_link_attribution',
|
| 77 |
'ga_use_universal_analytics',
|
| 78 |
'ga_anonymize_enabled',
|
| 79 |
'ga_ecommerce_tracking_enabled',
|
| 127 |
'checkboxgroup' => '',
|
| 128 |
'default' => get_option( 'woocommerce_ga_support_display_advertising' ) ? get_option( 'woocommerce_ga_support_display_advertising' ) : 'no' // Backwards compat
|
| 129 |
),
|
| 130 |
+
'ga_support_enhanced_link_attribution' => array(
|
| 131 |
+
'label' => __( 'Use Enhanced Link Attribution', 'woocommerce-google-analytics-integration' ),
|
| 132 |
+
'description' => sprintf( __( 'Set the Google Analytics code to support Enhanced Link Attribution. %sRead more about Enhanced Link Attribution%s.', 'woocommerce-google-analytics-integration' ), '<a href="https://support.google.com/analytics/answer/2558867?hl=en" target="_blank">', '</a>' ),
|
| 133 |
+
'type' => 'checkbox',
|
| 134 |
+
'checkboxgroup' => '',
|
| 135 |
+
'default' => get_option( 'woocommerce_ga_support_enhanced_link_attribution' ) ? get_option( 'woocommerce_ga_support_enhanced_link_attribution' ) : 'no' // Backwards compat
|
| 136 |
+
),
|
| 137 |
'ga_use_universal_analytics' => array(
|
| 138 |
'label' => __( 'Enable Universal Analytics', 'woocommerce-google-analytics-integration' ),
|
| 139 |
'description' => sprintf( __( 'Uses Universal Analytics instead of Classic Google Analytics. If you have <strong>not</strong> previously used Google Analytics on this site, check this box. Otherwise, %sfollow step 1 of the Universal Analytics upgrade guide.%s Enabling this setting will take care of step 2. %sRead more about Universal Analytics%s. Universal Analytics must be enabled to enable enhanced eCommerce.', 'woocommerce-google-analytics-integration' ), '<a href="https://developers.google.com/analytics/devguides/collection/upgrade/guide" target="_blank">', '</a>', '<a href="https://support.google.com/analytics/answer/2790010?hl=en" target="_blank">', '</a>' ),
|
| 233 |
*/
|
| 234 |
function track_options( $data ) {
|
| 235 |
$data['wc-google-analytics'] = array(
|
| 236 |
+
'standard_tracking_enabled' => $this->ga_standard_tracking_enabled,
|
| 237 |
+
'support_display_advertising' => $this->ga_support_display_advertising,
|
| 238 |
+
'support_enhanced_link_attribution' => $this->ga_support_enhanced_link_attribution,
|
| 239 |
+
'use_universal_analytics' => $this->ga_use_universal_analytics,
|
| 240 |
+
'anonymize_enabled' => $this->ga_anonymize_enabled,
|
| 241 |
+
'ecommerce_tracking_enabled' => $this->ga_ecommerce_tracking_enabled,
|
| 242 |
+
'event_tracking_enabled' => $this->ga_event_tracking_enabled
|
| 243 |
);
|
| 244 |
return $data;
|
| 245 |
}
|
| 360 |
$parameters = array();
|
| 361 |
$parameters['category'] = "'" . __( 'Products', 'woocommerce-google-analytics-integration' ) . "'";
|
| 362 |
$parameters['action'] = "'" . __( 'Add to Cart', 'woocommerce-google-analytics-integration' ) . "'";
|
| 363 |
+
$parameters['label'] = "'" . esc_js( $product->get_sku() ? __( 'ID:', 'woocommerce-google-analytics-integration' ) . ' ' . $product->get_sku() : "#" . $product->get_id() ) . "'";
|
| 364 |
|
| 365 |
if ( ! $this->disable_tracking( $this->ga_enhanced_ecommerce_tracking_enabled ) ) {
|
| 366 |
$code = "" . WC_Google_Analytics_JS::get_instance()->tracker_var() . "( 'ec:addProduct', {";
|
| 367 |
+
$code .= "'id': '" . esc_js( $product->get_sku() ? $product->get_sku() : ( '#' . $product->get_id() ) ) . "',";
|
| 368 |
+
$code .= "'name': '" . esc_js( $product->get_title() ) . "',";
|
| 369 |
$code .= "'quantity': $( 'input.qty' ).val() ? $( 'input.qty' ).val() : '1'";
|
| 370 |
$code .= "} );";
|
| 371 |
$parameters['enhanced'] = $code;
|
| 403 |
|
| 404 |
$item = WC()->cart->get_cart_item( $key );
|
| 405 |
$product = $item['data'];
|
| 406 |
+
$url = str_replace( 'href=', 'data-product_id="' . esc_attr( $product->get_id() ) . '" data-product_sku="' . esc_attr( $product->get_sku() ) . '" href=', $url );
|
| 407 |
return $url;
|
| 408 |
}
|
| 409 |
|
| 421 |
$parameters = array();
|
| 422 |
$parameters['category'] = "'" . __( 'Products', 'woocommerce-google-analytics-integration' ) . "'";
|
| 423 |
$parameters['action'] = "'" . __( 'Add to Cart', 'woocommerce-google-analytics-integration' ) . "'";
|
| 424 |
+
$parameters['label'] = "($(this).data('product_sku')) ? ($(this).data('product_sku')) : ('#' + $(this).data('product_id'))"; // Product SKU or ID
|
| 425 |
|
| 426 |
if ( ! $this->disable_tracking( $this->ga_enhanced_ecommerce_tracking_enabled ) ) {
|
| 427 |
$code = "" . WC_Google_Analytics_JS::get_instance()->tracker_var() . "( 'ec:addProduct', {";
|
| 428 |
+
$code .= "'id': ($(this).data('product_sku')) ? ($(this).data('product_sku')) : ('#' + $(this).data('product_id')),";
|
| 429 |
$code .= "'quantity': $(this).data('quantity')";
|
| 430 |
$code .= "} );";
|
| 431 |
$parameters['enhanced'] = $code;
|
package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"name": "woocommerce-google-analytics-integration",
|
| 3 |
"title": "WooCommerce Google Analytics Integration",
|
| 4 |
-
"version": "1.4.
|
| 5 |
"homepage": "https://wordpress.org/plugins/woocommerce-google-analytics-integration/",
|
| 6 |
"repository": {
|
| 7 |
"type": "git",
|
| 1 |
{
|
| 2 |
"name": "woocommerce-google-analytics-integration",
|
| 3 |
"title": "WooCommerce Google Analytics Integration",
|
| 4 |
+
"version": "1.4.1",
|
| 5 |
"homepage": "https://wordpress.org/plugins/woocommerce-google-analytics-integration/",
|
| 6 |
"repository": {
|
| 7 |
"type": "git",
|
readme.txt
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
=== WooCommerce Google Analytics Integration ===
|
| 2 |
-
Contributors: woothemes, claudiosanches
|
| 3 |
Tags: woocommerce, google analytics
|
| 4 |
Requires at least: 3.8
|
| 5 |
Tested up to: 4.5.2
|
| 6 |
-
Stable tag: 1.4.
|
| 7 |
License: GPLv3
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
| 9 |
|
|
@@ -64,7 +64,18 @@ Exact wording depends on the national data privacy laws and should be adjusted.
|
|
| 64 |
|
| 65 |
== Changelog ==
|
| 66 |
|
| 67 |
-
= 1.4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
* Feature - Support for enhanced eCommerce (tracking full store process from view to order)
|
| 69 |
* Tweak - Setting up the plugin is now clearer with some helpful links and clearer language
|
| 70 |
* Tweak - New filter on the ga global variable
|
|
@@ -103,3 +114,8 @@ Exact wording depends on the national data privacy laws and should be adjusted.
|
|
| 103 |
= 1.0 - 22/11/2013 =
|
| 104 |
|
| 105 |
* Initial release
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
=== WooCommerce Google Analytics Integration ===
|
| 2 |
+
Contributors: woothemes, claudiosanches, bor0
|
| 3 |
Tags: woocommerce, google analytics
|
| 4 |
Requires at least: 3.8
|
| 5 |
Tested up to: 4.5.2
|
| 6 |
+
Stable tag: 1.4.1
|
| 7 |
License: GPLv3
|
| 8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
| 9 |
|
| 64 |
|
| 65 |
== Changelog ==
|
| 66 |
|
| 67 |
+
= 1.4.1 - 01/05/2017 =
|
| 68 |
+
|
| 69 |
+
* Add - Filters for GA snippet (woocommerce_ga_snippet_head, woocommerce_ga_snippet_create, woocommerce_ga_snippet_require, woocommerce_ga_snippet_output)
|
| 70 |
+
* Add - Option to toggle on/off Enhanced Link Attribution
|
| 71 |
+
* Fix - JavaScript break by wrapping it in quotes
|
| 72 |
+
* Fix - Use ID and SKU data in a consistent way so that all products are correctly tracked.
|
| 73 |
+
* Fix - Updates for WooCommerce 3.0 compatibility.
|
| 74 |
+
* Add - Settings link to the plugin in the Plugins screen
|
| 75 |
+
* Fix - Fatal error on shortcode usage for empty product
|
| 76 |
+
|
| 77 |
+
= 1.4.0 - 20/11/2015 =
|
| 78 |
+
|
| 79 |
* Feature - Support for enhanced eCommerce (tracking full store process from view to order)
|
| 80 |
* Tweak - Setting up the plugin is now clearer with some helpful links and clearer language
|
| 81 |
* Tweak - New filter on the ga global variable
|
| 114 |
= 1.0 - 22/11/2013 =
|
| 115 |
|
| 116 |
* Initial release
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
== Upgrade Notice ==
|
| 120 |
+
= 1.4.0 =
|
| 121 |
+
Adds support for enhanced eCommerce (tracking full store process from view to order)
|
woocommerce-google-analytics-integration.php
CHANGED
|
@@ -3,9 +3,9 @@
|
|
| 3 |
* Plugin Name: WooCommerce Google Analytics Integration
|
| 4 |
* Plugin URI: http://wordpress.org/plugins/woocommerce-google-analytics-integration/
|
| 5 |
* Description: Allows Google Analytics tracking code to be inserted into WooCommerce store pages.
|
| 6 |
-
* Author:
|
| 7 |
-
* Author URI:
|
| 8 |
-
* Version: 1.4.
|
| 9 |
* License: GPLv2 or later
|
| 10 |
* Text Domain: woocommerce-google-analytics-integration
|
| 11 |
* Domain Path: languages/
|
|
@@ -27,7 +27,7 @@ class WC_Google_Analytics_Integration {
|
|
| 27 |
*
|
| 28 |
* @var string
|
| 29 |
*/
|
| 30 |
-
const VERSION = '1.4.
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Instance of this class.
|
|
@@ -52,6 +52,25 @@ class WC_Google_Analytics_Integration {
|
|
| 52 |
} else {
|
| 53 |
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
|
| 54 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 3 |
* Plugin Name: WooCommerce Google Analytics Integration
|
| 4 |
* Plugin URI: http://wordpress.org/plugins/woocommerce-google-analytics-integration/
|
| 5 |
* Description: Allows Google Analytics tracking code to be inserted into WooCommerce store pages.
|
| 6 |
+
* Author: WooCommerce
|
| 7 |
+
* Author URI: https://woocommerce.com
|
| 8 |
+
* Version: 1.4.1
|
| 9 |
* License: GPLv2 or later
|
| 10 |
* Text Domain: woocommerce-google-analytics-integration
|
| 11 |
* Domain Path: languages/
|
| 27 |
*
|
| 28 |
* @var string
|
| 29 |
*/
|
| 30 |
+
const VERSION = '1.4.1';
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Instance of this class.
|
| 52 |
} else {
|
| 53 |
add_action( 'admin_notices', array( $this, 'woocommerce_missing_notice' ) );
|
| 54 |
}
|
| 55 |
+
|
| 56 |
+
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_links' ) );
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
public function plugin_links( $links ) {
|
| 60 |
+
$settings_url = add_query_arg(
|
| 61 |
+
array(
|
| 62 |
+
'page' => 'wc-settings',
|
| 63 |
+
'tab' => 'integration',
|
| 64 |
+
),
|
| 65 |
+
admin_url( 'admin.php' )
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
$plugin_links = array(
|
| 69 |
+
'<a href="' . esc_url( $settings_url ) . '">' . __( 'Settings', 'woocommerce-google-analytics-integration' ) . '</a>',
|
| 70 |
+
'<a href="https://wordpress.org/support/plugin/woocommerce-google-analytics-integration">' . __( 'Support', 'woocommerce-google-analytics-integration' ) . '</a>',
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
return array_merge( $plugin_links, $links );
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
