Jetpack by WordPress.com - Version 5.4-beta3

Version Description

Download this release

Release Info

Developer dsmart
Plugin Icon 128x128 Jetpack by WordPress.com
Version 5.4-beta3
Comparing to
See all releases

Code changes from version 5.4-beta2 to 5.4-beta3

class.json-api-endpoints.php CHANGED
@@ -1069,7 +1069,7 @@ abstract class WPCOM_JSON_API_Endpoint {
1069
  $first_name = '';
1070
  $last_name = '';
1071
  $URL = $author->comment_author_url;
1072
- $avatar_URL = $this->api->get_avatar_url( $email );
1073
  $profile_URL = 'https://en.gravatar.com/' . md5( strtolower( trim( $email ) ) );
1074
  $nice = '';
1075
  $site_id = -1;
1069
  $first_name = '';
1070
  $last_name = '';
1071
  $URL = $author->comment_author_url;
1072
+ $avatar_URL = $this->api->get_avatar_url( $author );
1073
  $profile_URL = 'https://en.gravatar.com/' . md5( strtolower( trim( $email ) ) );
1074
  $nice = '';
1075
  $site_id = -1;
css/jetpack-rtl.css CHANGED
@@ -22,9 +22,6 @@ div[class^=gr_custom_container]{border:1px solid gray;border-radius:10px;padding
22
  .jetpack-image-container:after{clear:both}.jetpack-image-container:after,.jetpack-image-container:before{display:table;content:""}
23
  .widgets-multi-column-grid ul{overflow:hidden;padding:0;margin:0;list-style-type:none}.widgets-multi-column-grid ul li{background:100% 0;clear:none;float:right;margin:0 0 -3px -5px;padding:0 0 6px 8px;border:none;list-style-type:none!important}.widgets-multi-column-grid ul li a{background:100% 0;margin:0;padding:0;border:0}.widgets-multi-column-grid .avatar{vertical-align:middle}.widget_jetpack_my_community .avatar-240,.widget_jetpack_my_community .avatar-48{max-width:48px;max-height:48px}
24
  .widget.widget_authors li>ul,.widget_authors>ul{margin-right:inherit;padding-right:0}.widget_authors ul li li{padding-right:0}.widget_authors>ul>li{margin-bottom:1em;list-style:none}.widget_authors>ul>li+li{border-top:0}.widget.widget_authors img{margin-left:5px;margin-bottom:5px;vertical-align:middle;box-shadow:none}
25
- /*!
26
- * Do not modify this file directly. It is compiled SASS code.
27
- */#wp-admin-bar-jetpack-idc.hide{display:none}#wp-admin-bar-jetpack-idc .jp-idc-admin-bar{background:#fff;border-radius:2px;color:#23282d;padding:4px 8px;font-size:12px}#wpadminbar #wp-admin-bar-jetpack-idc .dashicons{color:#23282d;font-family:dashicons}#wpadminbar #wp-admin-bar-jetpack-idc .dashicons:before{font-size:16px}#wpadminbar #wp-admin-bar-jetpack-idc:hover .ab-item{background:inherit}#wpadminbar #wp-admin-bar-jetpack-idc:hover .jp-idc-admin-bar{background:#eee}
28
  .wpcnt{text-align:center;line-height:2}.wpa{position:relative;overflow:hidden;display:inline-block;max-width:100%}.wpa-about{position:absolute;top:5px;right:0;left:0;display:block;margin-top:0;color:#888;font:10px/1 "Open Sans",Arial,sans-serif!important;text-align:right!important;text-decoration:none!important;opacity:.85;border-bottom:none!important;box-shadow:none!important}.wpa .u>div{display:block;margin-top:5px;margin-bottom:1em}div.wpa>div{margin-top:20px}.wpa .u .adsbygoogle{display:block;margin-top:17px;margin-bottom:1em;background-color:transparent}
29
  .widget_eu_cookie_law_widget.widget{border:none;bottom:1em;display:none;right:1em;margin:0;padding:0;position:fixed;left:1em;width:auto;z-index:50001}#eu-cookie-law{background-color:#fff;border:1px solid #dedede;color:#2e4467;font-size:12px;line-height:1.5;overflow:hidden;padding:6px 15px 6px 6px;position:relative}#eu-cookie-law a,#eu-cookie-law a:active,#eu-cookie-law a:visited{color:inherit;cursor:inherit;text-decoration:underline}#eu-cookie-law a:hover{cursor:pointer;text-decoration:none}#eu-cookie-law.negative{background-color:#000;border:none;color:#fff}#eu-cookie-law input,#eu-cookie-law input:focus,#eu-cookie-law input:hover{background:#f3f3f3;border:1px solid #dedede;border-radius:4px;-moz-border-radius:3px;-webkit-border-radius:3px;color:#2e4453;cursor:pointer;display:inline;float:left;font-family:inherit;font-size:14px;font-weight:inherit;line-height:inherit;margin:0 5% 0 0;padding:8px 12px;position:static;text-transform:none}#eu-cookie-law.negative input,#eu-cookie-law.negative input:focus,#eu-cookie-law.negative input:hover{background:#282828;border-color:#535353;color:#fff}@media (max-width:600px){#eu-cookie-law{padding-bottom:55px}#eu-cookie-law input.accept{bottom:8px;position:absolute;left:8px}}
30
  .flickr-images{text-align:center}.flickr-size-thumbnail .flickr-images{-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-flow:row wrap;flex-flow:row wrap;-ms-flex-pack:center;justify-content:center}.flickr-images img{max-width:100%;margin:5px}
22
  .jetpack-image-container:after{clear:both}.jetpack-image-container:after,.jetpack-image-container:before{display:table;content:""}
23
  .widgets-multi-column-grid ul{overflow:hidden;padding:0;margin:0;list-style-type:none}.widgets-multi-column-grid ul li{background:100% 0;clear:none;float:right;margin:0 0 -3px -5px;padding:0 0 6px 8px;border:none;list-style-type:none!important}.widgets-multi-column-grid ul li a{background:100% 0;margin:0;padding:0;border:0}.widgets-multi-column-grid .avatar{vertical-align:middle}.widget_jetpack_my_community .avatar-240,.widget_jetpack_my_community .avatar-48{max-width:48px;max-height:48px}
24
  .widget.widget_authors li>ul,.widget_authors>ul{margin-right:inherit;padding-right:0}.widget_authors ul li li{padding-right:0}.widget_authors>ul>li{margin-bottom:1em;list-style:none}.widget_authors>ul>li+li{border-top:0}.widget.widget_authors img{margin-left:5px;margin-bottom:5px;vertical-align:middle;box-shadow:none}
 
 
 
25
  .wpcnt{text-align:center;line-height:2}.wpa{position:relative;overflow:hidden;display:inline-block;max-width:100%}.wpa-about{position:absolute;top:5px;right:0;left:0;display:block;margin-top:0;color:#888;font:10px/1 "Open Sans",Arial,sans-serif!important;text-align:right!important;text-decoration:none!important;opacity:.85;border-bottom:none!important;box-shadow:none!important}.wpa .u>div{display:block;margin-top:5px;margin-bottom:1em}div.wpa>div{margin-top:20px}.wpa .u .adsbygoogle{display:block;margin-top:17px;margin-bottom:1em;background-color:transparent}
26
  .widget_eu_cookie_law_widget.widget{border:none;bottom:1em;display:none;right:1em;margin:0;padding:0;position:fixed;left:1em;width:auto;z-index:50001}#eu-cookie-law{background-color:#fff;border:1px solid #dedede;color:#2e4467;font-size:12px;line-height:1.5;overflow:hidden;padding:6px 15px 6px 6px;position:relative}#eu-cookie-law a,#eu-cookie-law a:active,#eu-cookie-law a:visited{color:inherit;cursor:inherit;text-decoration:underline}#eu-cookie-law a:hover{cursor:pointer;text-decoration:none}#eu-cookie-law.negative{background-color:#000;border:none;color:#fff}#eu-cookie-law input,#eu-cookie-law input:focus,#eu-cookie-law input:hover{background:#f3f3f3;border:1px solid #dedede;border-radius:4px;-moz-border-radius:3px;-webkit-border-radius:3px;color:#2e4453;cursor:pointer;display:inline;float:left;font-family:inherit;font-size:14px;font-weight:inherit;line-height:inherit;margin:0 5% 0 0;padding:8px 12px;position:static;text-transform:none}#eu-cookie-law.negative input,#eu-cookie-law.negative input:focus,#eu-cookie-law.negative input:hover{background:#282828;border-color:#535353;color:#fff}@media (max-width:600px){#eu-cookie-law{padding-bottom:55px}#eu-cookie-law input.accept{bottom:8px;position:absolute;left:8px}}
27
  .flickr-images{text-align:center}.flickr-size-thumbnail .flickr-images{-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-flow:row wrap;flex-flow:row wrap;-ms-flex-pack:center;justify-content:center}.flickr-images img{max-width:100%;margin:5px}
css/jetpack.css CHANGED
@@ -22,9 +22,6 @@ div[class^=gr_custom_container]{border:1px solid gray;border-radius:10px;padding
22
  .jetpack-image-container:after{clear:both}.jetpack-image-container:after,.jetpack-image-container:before{display:table;content:""}
23
  .widgets-multi-column-grid ul{overflow:hidden;padding:0;margin:0;list-style-type:none}.widgets-multi-column-grid ul li{background:0 0;clear:none;float:left;margin:0 -5px -3px 0;padding:0 8px 6px 0;border:none;list-style-type:none!important}.widgets-multi-column-grid ul li a{background:0 0;margin:0;padding:0;border:0}.widgets-multi-column-grid .avatar{vertical-align:middle}.widget_jetpack_my_community .avatar-240,.widget_jetpack_my_community .avatar-48{max-width:48px;max-height:48px}
24
  .widget.widget_authors li>ul,.widget_authors>ul{margin-left:inherit;padding-left:0}.widget_authors ul li li{padding-left:0}.widget_authors>ul>li{margin-bottom:1em;list-style:none}.widget_authors>ul>li+li{border-top:0}.widget.widget_authors img{margin-right:5px;margin-bottom:5px;vertical-align:middle;box-shadow:none}
25
- /*!
26
- * Do not modify this file directly. It is compiled SASS code.
27
- */#wp-admin-bar-jetpack-idc.hide{display:none}#wp-admin-bar-jetpack-idc .jp-idc-admin-bar{background:#fff;border-radius:2px;color:#23282d;padding:4px 8px;font-size:12px}#wpadminbar #wp-admin-bar-jetpack-idc .dashicons{color:#23282d;font-family:dashicons}#wpadminbar #wp-admin-bar-jetpack-idc .dashicons:before{font-size:16px}#wpadminbar #wp-admin-bar-jetpack-idc:hover .ab-item{background:inherit}#wpadminbar #wp-admin-bar-jetpack-idc:hover .jp-idc-admin-bar{background:#eee}
28
  .wpcnt{text-align:center;line-height:2}.wpa{position:relative;overflow:hidden;display:inline-block;max-width:100%}.wpa-about{position:absolute;top:5px;left:0;right:0;display:block;margin-top:0;color:#888;font:10px/1 "Open Sans",Arial,sans-serif!important;text-align:left!important;text-decoration:none!important;opacity:.85;border-bottom:none!important;box-shadow:none!important}.wpa .u>div{display:block;margin-top:5px;margin-bottom:1em}div.wpa>div{margin-top:20px}.wpa .u .adsbygoogle{display:block;margin-top:17px;margin-bottom:1em;background-color:transparent}
29
  .widget_eu_cookie_law_widget.widget{border:none;bottom:1em;display:none;left:1em;margin:0;padding:0;position:fixed;right:1em;width:auto;z-index:50001}#eu-cookie-law{background-color:#fff;border:1px solid #dedede;color:#2e4467;font-size:12px;line-height:1.5;overflow:hidden;padding:6px 6px 6px 15px;position:relative}#eu-cookie-law a,#eu-cookie-law a:active,#eu-cookie-law a:visited{color:inherit;cursor:inherit;text-decoration:underline}#eu-cookie-law a:hover{cursor:pointer;text-decoration:none}#eu-cookie-law.negative{background-color:#000;border:none;color:#fff}#eu-cookie-law input,#eu-cookie-law input:focus,#eu-cookie-law input:hover{background:#f3f3f3;border:1px solid #dedede;border-radius:4px;-moz-border-radius:3px;-webkit-border-radius:3px;color:#2e4453;cursor:pointer;display:inline;float:right;font-family:inherit;font-size:14px;font-weight:inherit;line-height:inherit;margin:0 0 0 5%;padding:8px 12px;position:static;text-transform:none}#eu-cookie-law.negative input,#eu-cookie-law.negative input:focus,#eu-cookie-law.negative input:hover{background:#282828;border-color:#535353;color:#fff}@media (max-width:600px){#eu-cookie-law{padding-bottom:55px}#eu-cookie-law input.accept{bottom:8px;position:absolute;right:8px}}
30
  .flickr-images{text-align:center}.flickr-size-thumbnail .flickr-images{-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-flow:row wrap;flex-flow:row wrap;-ms-flex-pack:center;justify-content:center}.flickr-images img{max-width:100%;margin:5px}
22
  .jetpack-image-container:after{clear:both}.jetpack-image-container:after,.jetpack-image-container:before{display:table;content:""}
23
  .widgets-multi-column-grid ul{overflow:hidden;padding:0;margin:0;list-style-type:none}.widgets-multi-column-grid ul li{background:0 0;clear:none;float:left;margin:0 -5px -3px 0;padding:0 8px 6px 0;border:none;list-style-type:none!important}.widgets-multi-column-grid ul li a{background:0 0;margin:0;padding:0;border:0}.widgets-multi-column-grid .avatar{vertical-align:middle}.widget_jetpack_my_community .avatar-240,.widget_jetpack_my_community .avatar-48{max-width:48px;max-height:48px}
24
  .widget.widget_authors li>ul,.widget_authors>ul{margin-left:inherit;padding-left:0}.widget_authors ul li li{padding-left:0}.widget_authors>ul>li{margin-bottom:1em;list-style:none}.widget_authors>ul>li+li{border-top:0}.widget.widget_authors img{margin-right:5px;margin-bottom:5px;vertical-align:middle;box-shadow:none}
 
 
 
25
  .wpcnt{text-align:center;line-height:2}.wpa{position:relative;overflow:hidden;display:inline-block;max-width:100%}.wpa-about{position:absolute;top:5px;left:0;right:0;display:block;margin-top:0;color:#888;font:10px/1 "Open Sans",Arial,sans-serif!important;text-align:left!important;text-decoration:none!important;opacity:.85;border-bottom:none!important;box-shadow:none!important}.wpa .u>div{display:block;margin-top:5px;margin-bottom:1em}div.wpa>div{margin-top:20px}.wpa .u .adsbygoogle{display:block;margin-top:17px;margin-bottom:1em;background-color:transparent}
26
  .widget_eu_cookie_law_widget.widget{border:none;bottom:1em;display:none;left:1em;margin:0;padding:0;position:fixed;right:1em;width:auto;z-index:50001}#eu-cookie-law{background-color:#fff;border:1px solid #dedede;color:#2e4467;font-size:12px;line-height:1.5;overflow:hidden;padding:6px 6px 6px 15px;position:relative}#eu-cookie-law a,#eu-cookie-law a:active,#eu-cookie-law a:visited{color:inherit;cursor:inherit;text-decoration:underline}#eu-cookie-law a:hover{cursor:pointer;text-decoration:none}#eu-cookie-law.negative{background-color:#000;border:none;color:#fff}#eu-cookie-law input,#eu-cookie-law input:focus,#eu-cookie-law input:hover{background:#f3f3f3;border:1px solid #dedede;border-radius:4px;-moz-border-radius:3px;-webkit-border-radius:3px;color:#2e4453;cursor:pointer;display:inline;float:right;font-family:inherit;font-size:14px;font-weight:inherit;line-height:inherit;margin:0 0 0 5%;padding:8px 12px;position:static;text-transform:none}#eu-cookie-law.negative input,#eu-cookie-law.negative input:focus,#eu-cookie-law.negative input:hover{background:#282828;border-color:#535353;color:#fff}@media (max-width:600px){#eu-cookie-law{padding-bottom:55px}#eu-cookie-law input.accept{bottom:8px;position:absolute;right:8px}}
27
  .flickr-images{text-align:center}.flickr-size-thumbnail .flickr-images{-ms-flex-line-pack:justify;align-content:space-between;-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex;-ms-flex-flow:row wrap;flex-flow:row wrap;-ms-flex-pack:center;justify-content:center}.flickr-images img{max-width:100%;margin:5px}
jetpack.php CHANGED
@@ -5,7 +5,7 @@
5
  * Plugin URI: https://jetpack.com
6
  * Description: Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.
7
  * Author: Automattic
8
- * Version: 5.4-beta2
9
  * Author URI: https://jetpack.com
10
  * License: GPL2+
11
  * Text Domain: jetpack
@@ -14,7 +14,7 @@
14
 
15
  define( 'JETPACK__MINIMUM_WP_VERSION', '4.7' );
16
 
17
- define( 'JETPACK__VERSION', '5.4-beta2' );
18
  define( 'JETPACK_MASTER_USER', true );
19
  define( 'JETPACK__API_VERSION', 1 );
20
  define( 'JETPACK__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
5
  * Plugin URI: https://jetpack.com
6
  * Description: Bring the power of the WordPress.com cloud to your self-hosted WordPress. Jetpack enables you to connect your blog to a WordPress.com account to use the powerful features normally only available to WordPress.com users.
7
  * Author: Automattic
8
+ * Version: 5.4-beta3
9
  * Author URI: https://jetpack.com
10
  * License: GPL2+
11
  * Text Domain: jetpack
14
 
15
  define( 'JETPACK__MINIMUM_WP_VERSION', '4.7' );
16
 
17
+ define( 'JETPACK__VERSION', '5.4-beta3' );
18
  define( 'JETPACK_MASTER_USER', true );
19
  define( 'JETPACK__API_VERSION', 1 );
20
  define( 'JETPACK__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
modules/google-analytics/wp-google-analytics.php CHANGED
@@ -35,7 +35,10 @@ class Jetpack_Google_Analytics {
35
  * @return void
36
  */
37
  private function __construct() {
 
 
38
  add_action( 'wp_footer', array( $this, 'insert_code' ) );
 
39
  }
40
 
41
  /**
@@ -115,7 +118,7 @@ class Jetpack_Google_Analytics {
115
  $track = array();
116
  if ( is_404() ) {
117
  // This is a 404 and we are supposed to track them.
118
- $custom_vars[] = "_gaq.push( [ '_trackEvent', '404', document.location.href, document.referrer ] );";
119
  } elseif ( is_search() ) {
120
  // Set track for searches, if it's a search, and we are supposed to.
121
  $track['data'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // Input var okay.
@@ -131,17 +134,27 @@ class Jetpack_Google_Analytics {
131
  $custom_vars[] = "_gaq.push(['_trackPageview']);";
132
  }
133
 
 
 
 
 
 
 
 
 
 
 
134
  $async_code = "<!-- Jetpack Google Analytics -->
135
- <script type='text/javascript'>
136
- var _gaq = _gaq || [];
137
- %custom_vars%
138
 
139
- (function() {
140
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
141
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
142
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
143
- })();
144
- </script>";
145
 
146
  $custom_vars_string = implode( "\r\n", $custom_vars );
147
  $async_code = str_replace( '%custom_vars%', $custom_vars_string, $async_code );
@@ -163,6 +176,151 @@ class Jetpack_Google_Analytics {
163
 
164
  return '';
165
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
167
 
168
  global $jetpack_google_analytics;
35
  * @return void
36
  */
37
  private function __construct() {
38
+ add_filter( 'jetpack_wga_classic_custom_vars', array( $this, 'jetpack_wga_classic_anonymize_ip' ) );
39
+ add_filter( 'jetpack_wga_classic_custom_vars', array( $this, 'jetpack_wga_classic_track_purchases' ) );
40
  add_action( 'wp_footer', array( $this, 'insert_code' ) );
41
+ add_action( 'wp_footer', array( $this, 'jetpack_wga_classic_track_add_to_cart' ) );
42
  }
43
 
44
  /**
118
  $track = array();
119
  if ( is_404() ) {
120
  // This is a 404 and we are supposed to track them.
121
+ $custom_vars[] = "_gaq.push(['_trackEvent', '404', document.location.href, document.referrer]);";
122
  } elseif ( is_search() ) {
123
  // Set track for searches, if it's a search, and we are supposed to.
124
  $track['data'] = sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ); // Input var okay.
134
  $custom_vars[] = "_gaq.push(['_trackPageview']);";
135
  }
136
 
137
+ /**
138
+ * Allow for additional elements to be added to the classic Google Analytics queue (_gaq) array
139
+ *
140
+ * @since 5.4.0
141
+ *
142
+ * @param array $custom_vars Array of classic Google Analytics queue elements
143
+ */
144
+ $custom_vars = apply_filters( 'jetpack_wga_classic_custom_vars', $custom_vars );
145
+
146
+ // Ref: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce#Example
147
  $async_code = "<!-- Jetpack Google Analytics -->
148
+ <script type='text/javascript'>
149
+ var _gaq = _gaq || [];
150
+ %custom_vars%
151
 
152
+ (function() {
153
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
154
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
155
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
156
+ })();
157
+ </script>";
158
 
159
  $custom_vars_string = implode( "\r\n", $custom_vars );
160
  $async_code = str_replace( '%custom_vars%', $custom_vars_string, $async_code );
176
 
177
  return '';
178
  }
179
+
180
+ /**
181
+ * Used to filter in the anonymize IP snippet to the custom vars array for classic analytics
182
+ * Ref https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApi_gat#_gat._anonymizelp
183
+ * @param array custom vars to be filtered
184
+ * @return array possibly updated custom vars
185
+ */
186
+ public function jetpack_wga_classic_anonymize_ip( $custom_vars ) {
187
+ $o = get_option( 'jetpack_wga' );
188
+ $anonymize_ip = isset( $o[ 'anonymize_ip' ] ) ? $o[ 'anonymize_ip' ] : false;
189
+ if ( $anonymize_ip ) {
190
+ array_push( $custom_vars, "_gaq.push(['_gat._anonymizeIp']);" );
191
+ }
192
+
193
+ return $custom_vars;
194
+ }
195
+
196
+ /**
197
+ * Used to filter in the order details to the custom vars array for classic analytics
198
+ * @param array custom vars to be filtered
199
+ * @return array possibly updated custom vars
200
+ */
201
+ public function jetpack_wga_classic_track_purchases( $custom_vars ) {
202
+ global $wp;
203
+
204
+ // Ref: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce#Example
205
+ $o = get_option( 'jetpack_wga' );
206
+ $ec_track_purchases = isset( $o[ 'ec_track_purchases' ] ) ? $o[ 'ec_track_purchases' ] : false;
207
+ $minimum_woocommerce_active = class_exists( 'WooCommerce' ) && version_compare( WC_VERSION, '3.0', '>=' );
208
+ if ( $ec_track_purchases && $minimum_woocommerce_active && is_order_received_page() ) {
209
+ $order_id = isset( $wp->query_vars['order-received'] ) ? $wp->query_vars['order-received'] : 0;
210
+ if ( 0 < $order_id && 1 != get_post_meta( $order_id, '_ga_tracked', true ) ) {
211
+ $order = new WC_Order( $order_id );
212
+
213
+ // [ '_add_Trans', '123', 'Site Title', '21.00', '1.00', '5.00', 'Snohomish', 'WA', 'USA' ]
214
+ array_push(
215
+ $custom_vars,
216
+ sprintf(
217
+ '_gaq.push( %s );', json_encode(
218
+ array(
219
+ '_addTrans',
220
+ (string) $order->get_order_number(),
221
+ get_bloginfo( 'name' ),
222
+ (string) $order->get_total(),
223
+ (string) $order->get_total_tax(),
224
+ (string) $order->get_total_shipping(),
225
+ (string) $order->get_billing_city(),
226
+ (string) $order->get_billing_state(),
227
+ (string) $order->get_billing_country()
228
+ )
229
+ )
230
+ )
231
+ );
232
+
233
+ // Order items
234
+ if ( $order->get_items() ) {
235
+ foreach ( $order->get_items() as $item ) {
236
+ $product = $order->get_product_from_item( $item );
237
+ $product_sku_or_id = $product->get_sku() ? $product->get_sku() : $product->get_id();
238
+
239
+ array_push(
240
+ $custom_vars,
241
+ sprintf(
242
+ '_gaq.push( %s );', json_encode(
243
+ array(
244
+ '_addItem',
245
+ (string) $order->get_order_number(),
246
+ (string) $product_sku_or_id,
247
+ $item['name'],
248
+ self::get_product_categories_concatenated( $product ),
249
+ (string) $order->get_item_total( $item ),
250
+ (string) $item['qty']
251
+ )
252
+ )
253
+ )
254
+ );
255
+ }
256
+ } // get_items
257
+
258
+ // Mark the order as tracked
259
+ update_post_meta( $order_id, '_ga_tracked', 1 );
260
+ array_push( $custom_vars, "_gaq.push(['_trackTrans']);" );
261
+ } // order not yet tracked
262
+ } // is order received page
263
+
264
+ return $custom_vars;
265
+ }
266
+
267
+ /**
268
+ * Gets product categories or varation attributes as a formatted concatenated string
269
+ * @param WC_Product
270
+ * @return string
271
+ */
272
+ public function get_product_categories_concatenated( $product ) {
273
+ $variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : '';
274
+ if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
275
+ $line = wc_get_formatted_variation( $variation_data, true );
276
+ } else {
277
+ $out = array();
278
+ $categories = get_the_terms( $product->get_id(), 'product_cat' );
279
+ if ( $categories ) {
280
+ foreach ( $categories as $category ) {
281
+ $out[] = $category->name;
282
+ }
283
+ }
284
+ $line = join( "/", $out );
285
+ }
286
+ return $line;
287
+ }
288
+
289
+ /**
290
+ * Used to add footer javascript to track user clicking on add-to-cart buttons
291
+ * on single views (.single_add_to_cart_button) and list views (.add_to_cart_button)
292
+ */
293
+ public function jetpack_wga_classic_track_add_to_cart() {
294
+ $tracking_id = $this->_get_tracking_code();
295
+ if ( empty( $tracking_id ) ) {
296
+ return;
297
+ }
298
+
299
+ $o = get_option( 'jetpack_wga' );
300
+ $ec_track_add_to_cart = isset( $o[ 'ec_track_add_to_cart' ] ) ? $o[ 'ec_track_add_to_cart' ] : false;
301
+ if ( $ec_track_add_to_cart ) {
302
+ if ( is_product() ) { // product page
303
+ global $product;
304
+ $product_sku_or_id = $product->get_sku() ? $product->get_sku() : "#" + $product->get_id();
305
+ wc_enqueue_js(
306
+ "jQuery( function( $ ) {
307
+ $( '.single_add_to_cart_button' ).click( function() {
308
+ _gaq.push(['_trackEvent', 'Products', 'Add to Cart', '#" . esc_js( $product_sku_or_id ) . "']);
309
+ } );
310
+ } );"
311
+ );
312
+ } else if ( is_woocommerce() ) { // any other page that uses templates (like product lists, archives, etc)
313
+ wc_enqueue_js(
314
+ "jQuery( function( $ ) {
315
+ $( '.add_to_cart_button:not(.product_type_variable, .product_type_grouped)' ).click( function() {
316
+ var label = $( this ).data( 'product_sku' ) ? $( this ).data( 'product_sku' ) : '#' + $( this ).data( 'product_id' );
317
+ _gaq.push(['_trackEvent', 'Products', 'Add to Cart', label]);
318
+ } );
319
+ } );"
320
+ );
321
+ }
322
+ }
323
+ }
324
  }
325
 
326
  global $jetpack_google_analytics;
readme.txt CHANGED
@@ -114,7 +114,8 @@ There are opportunities for developers at all levels to contribute. [Learn more
114
 
115
  **Enhancements**
116
  * Add Schema.org markup to the Contact Info Widget.
117
- * Add a new "Date" field to the Contact Form.
 
118
  * Do not show any update notices when in [development mode](http://jetpack.com/support/development-mode).
119
  * Improve our documentation to help contributors set up a unit testing environment.
120
  * Avoid conflicts between Jetpack's Infinite Scroll and other Infinite Scroll plugins.
114
 
115
  **Enhancements**
116
  * Add Schema.org markup to the Contact Info Widget.
117
+ * Add a new "Date" field to the Contact Form.
118
+ * Added support in the Google Analytics feature for IP anonymization and basic WooCommerce tracking.
119
  * Do not show any update notices when in [development mode](http://jetpack.com/support/development-mode).
120
  * Improve our documentation to help contributors set up a unit testing environment.
121
  * Avoid conflicts between Jetpack's Infinite Scroll and other Infinite Scroll plugins.