Skip to content

Commit 4313fa6

Browse files
authored
Pagespeed 2.3.0 Adjustments (BoldGrid#660)
* Fixed placeholder issue. Fixed grammar issue. Fixed breakdown/recommendation block width issues if the data table is too broad. Added links to URLs within data breakdown to allow users to view reported URLs/files. Fixed localization issues under certain translations that would break JavaScript. * Added missing title attributes in allowed tags. Updated URL breakdown items for better escaping. Added the absent breakdown for "source" items. * Added clarification comment for the URL field conditionals to explain why the else doesn't escape the value. * Added GA tracking for user interaction. Updated JS register to match the format of other enqueues. * Updated escaping of JS/CSS files in enqueue/register. * Updated GA send format for better readability. I removed unused code from PageSpeed widget JS.
1 parent 1d299a9 commit 4313fa6

4 files changed

Lines changed: 75 additions & 35 deletions

File tree

PageSpeed_Page.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function run() {
3838
public static function admin_print_scripts_w3tc_pagespeed() {
3939
wp_register_script(
4040
'w3tc-pagespeed',
41-
esc_url( plugin_dir_url( __FILE__ ) . 'PageSpeed_Page_View.js' ),
41+
esc_url( plugins_url( 'PageSpeed_Page_View.js', W3TC_FILE ) ),
4242
array(),
4343
W3TC_VERSION,
4444
true
@@ -57,7 +57,7 @@ public static function admin_print_scripts_w3tc_pagespeed() {
5757

5858
wp_enqueue_style(
5959
'w3tc-pagespeed',
60-
plugins_url( 'PageSpeed_Page_View.css', W3TC_FILE ),
60+
esc_url( plugins_url( 'PageSpeed_Page_View.css', W3TC_FILE ) ),
6161
array(),
6262
W3TC_VERSION
6363
);

PageSpeed_Page_View.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ jQuery(document).ready(function ($) {
6767
* @return void
6868
*/
6969
function w3tcps_breakdown_items_toggle() {
70+
if (window.w3tc_ga) {
71+
w3tc_ga(
72+
'send',
73+
'event',
74+
{
75+
eventCategory: 'w3tc_pagespeed',
76+
eventAction: 'metric',
77+
eventLabel: $(this).text(),
78+
eventValue: 0,
79+
transport: 'beacon'
80+
}
81+
);
82+
}
83+
7084
$(this).find('.dashicons').toggleClass("dashicons-arrow-up-alt2 dashicons-arrow-down-alt2");
7185
$(this).next().slideToggle();
7286
}
@@ -79,6 +93,20 @@ jQuery(document).ready(function ($) {
7993
* @return void
8094
*/
8195
function w3tcps_mobile_toggle() {
96+
if (window.w3tc_ga) {
97+
w3tc_ga(
98+
'send',
99+
'event',
100+
{
101+
eventCategory: 'w3tc_pagespeed',
102+
eventAction: 'mobile_tab',
103+
eventLabel: $('#w3tcps_control_mobile').text(),
104+
eventValue: 0,
105+
transport: 'beacon'
106+
}
107+
);
108+
}
109+
82110
$('#w3tcps_control_desktop').removeClass('nav-tab-active');
83111
$('#w3tcps_desktop').hide();
84112
$('#w3tcps_control_mobile').addClass('nav-tab-active');
@@ -93,6 +121,20 @@ jQuery(document).ready(function ($) {
93121
* @return void
94122
*/
95123
function w3tcps_desktop_toggle() {
124+
if (window.w3tc_ga) {
125+
w3tc_ga(
126+
'send',
127+
'event',
128+
{
129+
eventCategory: 'w3tc_pagespeed',
130+
eventAction: 'desktop_tab',
131+
eventLabel: $('#w3tcps_control_desktop').text(),
132+
eventValue: 0,
133+
transport: 'beacon'
134+
}
135+
);
136+
}
137+
96138
$('#w3tcps_control_mobile').removeClass('nav-tab-active');
97139
$('#w3tcps_mobile').hide();
98140
$('#w3tcps_control_desktop').addClass('nav-tab-active');
@@ -108,6 +150,21 @@ jQuery(document).ready(function ($) {
108150
*/
109151
function w3tcps_audit_filter(event) {
110152
event.preventDefault();
153+
154+
if (window.w3tc_ga) {
155+
w3tc_ga(
156+
'send',
157+
'event',
158+
{
159+
eventCategory: 'w3tc_pagespeed',
160+
eventAction: 'filter_tab',
161+
eventLabel: $(this).text(),
162+
eventValue: 0,
163+
transport: 'beacon'
164+
}
165+
);
166+
}
167+
111168
if ('ALL' === $(this).text()) {
112169
$('.w3tcps_breakdown .audits').show();
113170
} else if ($(this).text().trim) {
@@ -188,6 +245,20 @@ jQuery(document).ready(function ($) {
188245
$(document).on('click', '.copyurl', w3tcps_copyurl);
189246

190247
$('.w3tcps_content').on('click', '.w3tcps_analyze', function () {
248+
if (window.w3tc_ga) {
249+
w3tc_ga(
250+
'send',
251+
'event',
252+
{
253+
eventCategory: 'w3tc_pagespeed',
254+
eventAction: 're_analyze',
255+
eventLabel: $(this).closest('.page_post').find('.w3tcps_buttons').attr('page_post_url'),
256+
eventValue: 0,
257+
transport: 'beacon'
258+
}
259+
);
260+
}
261+
191262
w3tcps_analyze($(this).closest('.page_post'), true);
192263
});
193264

PageSpeed_Widget.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function run() {
4040
public static function admin_print_scripts_w3tc_pagespeed_widget() {
4141
wp_register_script(
4242
'w3tc-widget-pagespeed',
43-
plugins_url( 'PageSpeed_Widget_View.js', W3TC_FILE ),
43+
esc_url( plugins_url( 'PageSpeed_Widget_View.js', W3TC_FILE ) ),
4444
array(),
4545
W3TC_VERSION,
4646
'true'
@@ -58,7 +58,7 @@ public static function admin_print_scripts_w3tc_pagespeed_widget() {
5858

5959
wp_enqueue_style(
6060
'w3tc-widget-pagespeed',
61-
plugins_url( 'PageSpeed_Widget_View.css', W3TC_FILE ),
61+
esc_url( plugins_url( 'PageSpeed_Widget_View.css', W3TC_FILE ) ),
6262
array(),
6363
W3TC_VERSION
6464
);

PageSpeed_Widget_View.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,6 @@ jQuery(document).ready(function ($) {
5252
});
5353
}
5454

55-
/**
56-
* Toggle mobile view.
57-
*
58-
* @since 2.3.0
59-
*
60-
* @return void
61-
*/
62-
function w3tcps_mobile_toggle() {
63-
$('#w3tcps_control_desktop').removeClass('nav-tab-active');
64-
$('#w3tcps_desktop').hide();
65-
$('#w3tcps_control_mobile').addClass('nav-tab-active');
66-
$('#w3tcps_mobile').show();
67-
}
68-
69-
/**
70-
* Toggle desktop view.
71-
*
72-
* @since 2.3.0
73-
*
74-
* @return void
75-
*/
76-
function w3tcps_desktop_toggle() {
77-
$('#w3tcps_control_mobile').removeClass('nav-tab-active');
78-
$('#w3tcps_mobile').hide();
79-
$('#w3tcps_control_desktop').addClass('nav-tab-active');
80-
$('#w3tcps_desktop').show();
81-
}
82-
83-
$(document).on('click', '#w3tcps_control_mobile', w3tcps_mobile_toggle);
84-
$(document).on('click', '#w3tcps_control_desktop', w3tcps_desktop_toggle);
85-
8655
$('.w3tcps_buttons').on('click', '.w3tcps_refresh', function () {
8756
w3tcps_load(true);
8857
});

0 commit comments

Comments
 (0)