PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.4.1
ShareThis Dashboard for Google Analytics v2.4.1
3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.0.0 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.3.0 3.3.1
googleanalytics / js / googleanalytics_page.js
googleanalytics / js Last commit date
googleanalytics.js 5 years ago googleanalytics_createprop.js 5 years ago googleanalytics_dashboard.js 9 years ago googleanalytics_page.js 5 years ago
googleanalytics_page.js
658 lines
1 const GA_ACCESS_CODE_MODAL_ID = "ga_access_code_modal";
2 const GA_DEBUG_MODAL_ID = "ga_debug_modal";
3 const GA_DEBUG_MODAL_CONTENT_ID = "ga_debug_modal_content";
4 const GA_DEBUG_EMAIL = "ga_debug_email";
5 const GA_DEBUG_DESCRIPTION = "ga_debug_description";
6 const GA_ACCESS_CODE_TMP_ID = "ga_access_code_tmp";
7 const GA_ACCESS_CODE_ID = "ga_access_code";
8 const GA_FORM_ID = "ga_form";
9 const GA_MODAL_CLOSE_ID = 'ga_close';
10 const GA_MODAL_BTN_CLOSE_ID = 'ga_btn_close';
11 const GA_GOOGLE_AUTH_BTN_ID = 'ga_authorize_with_google_button';
12 const GA_SAVE_ACCESS_CODE_BTN_ID = 'ga_save_access_code';
13 const GA_AUTHENTICATION_CODE_ERROR = 'That looks like your Google Analytics Tracking ID. Please enter the authentication token in this space. See here for <a href="https://cl.ly/1y1N1A3h0s1t" target="_blank">a walkthrough</a> of how to do it.';
14
15 (function ($) {
16 ga_popup = {
17 url: '',
18 authorize: function (e, url) {
19 e.preventDefault();
20 ga_popup.url = url;
21 $('#' + GA_ACCESS_CODE_MODAL_ID).appendTo("body").show();
22 ga_popup.open();
23 },
24 open: function () {
25 const p_width = Math.round(screen.width / 2);
26 const p_height = Math.round(screen.height / 2);
27 const p_left = Math.round(p_width / 2);
28 const p_top = 300;
29 window.open(ga_popup.url, 'ga_auth_popup', 'width=' + p_width + ',height='
30 + p_height + ',top=' + p_top + ',left=' + p_left);
31 },
32 saveAccessCode: function (e) {
33 e.preventDefault();
34 e.target.disabled = 'disabled';
35 ga_loader.show();
36 const ac_tmp = $('#' + GA_ACCESS_CODE_TMP_ID).val();
37 if (ga_popup.validateCode(e, ac_tmp)) {
38 $('#' + GA_ACCESS_CODE_ID).val(ac_tmp);
39 $('#' + GA_FORM_ID).submit();
40 }
41 },
42 validateCode: function (e, code) {
43 if (!code){
44 ga_loader.hide();
45 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
46 return false;
47 }
48 else if (code.substring(0, 2) == 'UA'){
49 $('#ga_code_error').show().html(GA_AUTHENTICATION_CODE_ERROR);
50 ga_loader.hide();
51 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
52 return false;
53 }
54 return true;
55 }
56 };
57
58 ga_modal = {
59 hide: function () {
60 $('#' + GA_ACCESS_CODE_MODAL_ID).hide();
61 $('#' + GA_DEBUG_MODAL_ID).hide();
62 ga_loader.hide();
63 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
64 }
65 };
66
67 ga_events = {
68
69 /**
70 * Send Demographic data.
71 *
72 * @param data
73 */
74 sendDemoData: function(demoData) {
75
76 // Send demographic data.
77 $.ajax( {
78 url: 'https://platform-api.sharethis.com/v1.0/property?id=' + ga_property_id + '&secret=' + ga_secret_id,
79 method: 'PUT',
80 async: false,
81 contentType: 'application/json; charset=utf-8',
82 data: JSON.stringify( {
83 "demographics": demoData
84 } ),
85 success: function( results ) {
86 }
87 } );
88 },
89 /**
90 * Returns gdpr onboarding config values.
91 */
92 setGDPRConfig: function(isGDPR) {
93
94 /**
95 * Check if ad blocker exists and notify if so.
96 */
97 $(document).ready(function(){
98 if($("#detectadblock").height() > 0) {
99 } else {
100 $('#adblocker-notice').show();
101 }
102 });
103
104 if (!isGDPR || undefined === gaGdprConfig) {
105 return;
106 }
107
108 var config = JSON.parse(gaGdprConfig);
109
110 $('.gdpr-platform input[name="gdpr-enable"]').prop('checked', config['enabled'] === 'true');
111 $('#sharethis-publisher-name').val(config['publisher_name']);
112 $(`#sharethis-user-type option[value="${config['display']}"]` ).attr('selected',true);
113 $(`#sharethis-consent-type option[value="${config['scope']}"]`).attr('selected', true);
114 $(`#sharethis-form-color .color[data-value="${config['color']}"]`).addClass('selected');
115 $(`#st-language option[value="${config['language']}"]`).attr('selected', true);
116
117 if (undefined !== config['publisher_purposes']) {
118 $( "#publisher-purpose .purpose-item input" ).prop('checked', false);
119
120 config['publisher_purposes'].map( ( purpVal ) => {
121 var legit = 'true' === purpVal['legitimate_interest'] || true === purpVal['legitimate_interest'];
122 var consent = 'false' === purpVal['legitimate_interest'] || false === purpVal['legitimate_interest'];
123
124 $( `#publisher-purpose .purpose-item input[name="purposes[${purpVal.id}]"][value="legitimate"]` ).prop( 'checked', legit );
125 $( `#publisher-purpose .purpose-item input[name="purposes[${purpVal.id}]"][value="consent"]` ).prop( 'checked', consent );
126 } );
127 }
128
129 if (undefined !== config['publisher_restrictions']) {
130 $( ".vendor-table-cell-wrapper input" ).prop('checked', false);
131
132 $.map(config['publisher_restrictions'], function (id, venVal ) {
133 if(id) {
134 $( `input[type="checkbox"][data-id="${venVal}"]` ).prop( 'checked', true );
135 }
136 } );
137 }
138 },
139 scrollToAnchor: function(aid) {
140 var aTag = $("a[name='"+ aid.toLowerCase() +"']");
141
142 $('.vendor-table-body').animate({
143 scrollTop: 0
144 }, 0).animate({
145 scrollTop: aTag.offset().top - 740
146 }, 0);
147 },
148
149 click: function (selector, callback) {
150 $(selector).live('click', callback);
151 },
152 codeManuallyCallback: function (features_enabled) {
153 var checkbox = $('#ga_enter_code_manually');
154 if ( features_enabled ) {
155 if ( checkbox.is(':checked') ) {
156 if (confirm('Warning: If you enter your Tracking ID manually, Analytics statistics will not be shown.')) {
157 setTimeout(function () {
158 $('#ga_authorize_with_google_button').attr('disabled','disabled').next().show();
159 $('#ga_account_selector').attr('disabled', 'disabled');
160 $('#ga_manually_wrapper').show();
161 }, 350);
162
163 } else {
164 setTimeout(function () {
165 checkbox.removeProp('checked');
166 }, 350);
167 }
168 } else { // disable
169 setTimeout(function () {
170 $('#ga_authorize_with_google_button').removeAttr('disabled').next().hide();
171 $('#ga_account_selector').removeAttr('disabled');
172 $('#ga_manually_wrapper').hide();
173 }, 350);
174 }
175 }
176 },
177 initModalEvents: function () {
178 $('body').on('click', '#close-review-us', function() {
179 var dataObj = {},
180 self = this;
181 dataObj['action'] = "ga_ajax_hide_review";
182 dataObj[GA_NONCE_FIELD] = GA_NONCE;
183
184 $.ajax({
185 type: "post",
186 dataType: "json",
187 url: ajaxurl,
188 data: dataObj,
189 success: function (response) {
190 $('.ga-review-us').fadeOut();
191 }
192 });
193 });
194
195 $('#' + GA_GOOGLE_AUTH_BTN_ID).on('click', function () {
196 $('#' + GA_ACCESS_CODE_TMP_ID).focus();
197 });
198
199 $('#' + GA_MODAL_CLOSE_ID + ', #' + GA_MODAL_BTN_CLOSE_ID + ', #' + GA_DEBUG_MODAL_ID ).on('click', function () {
200 ga_modal.hide();
201 });
202
203 $( '#copy-debug' ).on( 'click', function() {
204 var copiedText = $( '#ga_debug_info' );
205
206 copiedText.select();
207 document.execCommand( 'copy' );
208 } );
209
210 $('#' + GA_DEBUG_MODAL_CONTENT_ID ).click(function(event){
211 event.stopPropagation();
212 });
213 },
214
215 getConfig: function () {
216 var config,
217 enabled = $('input[name="gdpr-enable"]').is(':checked'),
218 publisherPurposes = [],
219 display = $( '#sharethis-user-type option:selected' ).val(),
220 name = $( '#sharethis-publisher-name' ).val(),
221 scope = $( '#sharethis-consent-type option:selected' ).val(),
222 color = $( '#sharethis-form-color .color.selected' ).attr('data-value'),
223 publisherRestrictions = {},
224 language = $( '#st-language' ).val();
225
226 $('#publisher-purpose input:checked').each( function( index, value ) {
227 var theId = $(value).attr('data-id'),
228 legit = 'consent' !== $(value).val();
229
230 publisherPurposes.push({ 'id': theId, 'legitimate_interest' : legit });
231 });
232
233 $('.vendor-table-cell-wrapper label input:checked').each( function( index, value ) {
234 var vendorId = $(value).attr('data-id');
235 if (vendorId) {
236 publisherRestrictions[vendorId] = true;
237 }
238 });
239
240 config = {
241 enabled: enabled,
242 display: display,
243 publisher_name: name,
244 publisher_purposes: publisherPurposes,
245 publisher_restrictions: publisherRestrictions,
246 language: language,
247 color: color,
248 scope: scope,
249 };
250
251 return config;
252 },
253
254 enableGdpr: function () {
255 var timer = '';
256 this.$gdprContainer = $('.gdpr-platform');
257
258 // New color select.
259 this.$gdprContainer.on('click', "#sharethis-form-color .color", function() {
260 $('#sharethis-form-color .color').removeClass('selected');
261 $(this).addClass('selected');
262 });
263
264 // clear or show choices.
265 this.$gdprContainer.on('click', '#clear-choices', function(e) {
266 e.preventDefault();
267 e.stopPropagation();
268
269 $( '.purpose-item input' ).prop( 'checked', false );
270 });
271
272 // clear or show choices.
273 this.$gdprContainer.on('click', '#see-st-choices', function(e) {
274 e.preventDefault();
275 e.stopPropagation();
276 $('.purpose-item input[name="purposes[1]"]').prop('checked', true);
277 $('.purpose-item input[name="purposes[3]"][value="consent"]').prop('checked', true);
278 $('.purpose-item input[name="purposes[5]"][value="consent"]').prop('checked', true);
279 $('.purpose-item input[name="purposes[6]"][value="consent"]').prop('checked', true);
280 $('.purpose-item input[name="purposes[9]"][value="legitimate"]').prop('checked', true);
281 $('.purpose-item input[name="purposes[10]"][value="legitimate"]').prop('checked', true);
282 });
283
284 // Uncheck radio if click on selected box.
285 this.$gdprContainer.on( 'click', '.lever', (e) => {
286 e.preventDefault();
287 e.stopPropagation();
288
289 const theInput = $( e.currentTarget ).siblings( 'input' );
290
291 if ( theInput.is( ':checked' ) ) {
292 $( `input[name="${theInput.attr( 'name' )}"]` ).prop( 'checked', false )
293 } else {
294 theInput.prop( 'checked', true )
295 }
296 } );
297
298 // Toggle button menus when arrows are clicked.
299 $( 'body' ).on( 'click', '.accor-wrap .accor-tab', function() {
300 var type = $( this ).find( 'span.accor-arrow' );
301
302 var closestButton = $( type ).parent( '.accor-tab' ).parent( '.accor-wrap' );
303
304 if ( '' === type.html() ) {
305
306 // Show the button configs.
307 closestButton.find( '.accor-content' ).slideDown();
308
309 // Change the icon next to title.
310 closestButton.find( '.accor-arrow' ).html( '&#9660;' );
311 } else {
312
313 // Show the button configs.
314 closestButton.find( '.accor-content' ).slideUp();
315
316 // Change the icon next to title.
317 closestButton.find( '.accor-arrow' ).html( '&#9658;' );
318 }
319 } );
320
321 $('body').on('click', '.demo-enable-popup .close-demo-modal', function(e) {
322 e.preventDefault();
323 e.stopPropagation();
324 $('.demo-enable-popup').removeClass('engage');
325 });
326
327 $('body').on('click', '#demographic-popup', function(e) {
328 e.preventDefault();
329 e.stopPropagation();
330 $('.demo-enable-popup').addClass('engage');
331 });
332
333 $('body').on('click', '#enable-demographic, #Enable-demographic', function(e) {
334 e.preventDefault();
335 e.stopPropagation();
336 ga_events.enableDemographic('enable');
337 });
338
339
340 $('body').on('click', '#Disable-demographic', function(e) {
341 e.preventDefault();
342 e.stopPropagation();
343 ga_events.enableDemographic('disable');
344 });
345
346 // Enable GDPR tool.
347 $('body').on('click', '.gdpr-submit', function(e) {
348 e.preventDefault();
349 e.stopPropagation();
350
351 var dataObj = {},
352 self = this,
353 config = ga_events.getConfig();
354
355 theData = JSON.stringify( {
356 'secret': ga_secret_id,
357 'id': ga_property_id,
358 'product': 'gdpr-compliance-tool-v2',
359 'config': config
360 } );
361
362 // Send new button status value.
363 $.ajax( {
364 url: 'https://platform-api.sharethis.com/v1.0/property/product',
365 method: 'POST',
366 async: false,
367 contentType: 'application/json; charset=utf-8',
368 data: theData,
369 success: function( results ) {
370 }
371 } );
372
373 dataObj['action'] = "ga_ajax_enable_gdpr";
374 dataObj['nonce'] = 'true';
375 dataObj['config'] = config;
376
377 $.ajax({
378 type: "post",
379 dataType: "json",
380 url: ajaxurl,
381 data: dataObj,
382 success: function (response) {
383 window.location.reload();
384 }
385 });
386 });
387
388
389 // Enable GDPR tool.
390 $('body').on('click', '.gdpr-enable', function(e) {
391 e.preventDefault();
392 e.stopPropagation();
393
394 var dataObj = {},
395 self = this,
396 config = ga_events.getConfig();
397
398 if ($('body').hasClass('google-analytics_page_googleanalytics-settings')) {
399 config = {
400 enabled: true,
401 display: 'eu',
402 publisher_name: '',
403 publisher_purposes: [],
404 language: 'en',
405 color: '',
406 scope: 'global',
407 };
408 }
409
410 theData = JSON.stringify( {
411 'secret': ga_secret_id,
412 'id': ga_property_id,
413 'product': 'gdpr-compliance-tool-v2',
414 'config': config
415 } );
416
417 // Send new button status value.
418 $.ajax( {
419 url: 'https://platform-api.sharethis.com/v1.0/property/product',
420 method: 'POST',
421 async: false,
422 contentType: 'application/json; charset=utf-8',
423 data: theData,
424 success: function( results ) {
425 }
426 } );
427
428 dataObj['action'] = "ga_ajax_enable_gdpr";
429 dataObj['nonce'] = 'true';
430 dataObj['config'] = config;
431
432 $.ajax({
433 type: "post",
434 dataType: "json",
435 url: ajaxurl,
436 data: dataObj,
437 success: function (response) {
438 window.location.href = siteAdminUrl + 'admin.php?page=googleanalytics%2Fgdpr';
439 }
440 });
441 });
442
443 // Scroll to anchor in vendor list.
444 // Send user input to category search AFTER they stop typing.
445 $('body').on( 'keyup', '.vendor-search input', function( e ) {
446 clearTimeout( timer );
447
448 timer = setTimeout( function() {
449 ga_events.scrollToAnchor($(this).val());
450 }.bind( this, ga_events ), 500 );
451 } );
452 },
453
454 enableDemographic: function(disable) {
455 var dataObj = {};
456
457 dataObj['action'] = "ga_ajax_enable_demographic";
458 dataObj['nonce'] = ga_demo_nonce;
459 dataObj['enabled'] = 'disable' === disable ? 'false' : 'true';
460
461 $.ajax({
462 type: "post",
463 dataType: "json",
464 url: ajaxurl,
465 data: dataObj,
466 success: function (response) {
467 window.location.reload();
468 }
469 });
470 }
471 };
472
473 /**
474 * Handles "disable all features" switch button
475 * @type {{init: ga_switcher.init}}
476 */
477 ga_switcher = {
478 init: function (state) {
479 var checkbox = $("#ga-disable");
480
481 if (state) {
482 checkbox.prop('checked', 'checked');
483 } else {
484 checkbox.removeProp('checked');
485 }
486
487 $(".ga-slider-disable").on("click", function (e) {
488 var manually_enter_not_checked = $('#ga_enter_code_manually').not(':checked');
489 if (checkbox.not(':checked').length > 0) {
490 if (confirm('This will disable Dashboards and Google API')) {
491 setTimeout(function () {
492 window.location.href = GA_DISABLE_FEATURE_URL;
493 }, 350);
494 } else {
495 setTimeout(function () {
496 checkbox.removeProp('checked');
497 }, 350);
498 }
499 } else { // disable
500 setTimeout(function () {
501 window.location.href = GA_ENABLE_FEATURE_URL;
502 }, 350);
503 }
504 });
505 }
506 };
507
508 $(document).ready(function () {
509 ga_events.initModalEvents();
510 ga_events.enableGdpr();
511 ga_events.setGDPRConfig($('body').hasClass('google-analytics_page_googleanalytics-gdpr'));
512 });
513
514 const offset = 50;
515 const minWidth = 350;
516 const wrapperSelector = '#ga-stats-container';
517 const chartContainer = 'chart_div';
518 const demoChartGenderContainer = 'demo_chart_gender_div';
519 const demoChartAgeContainer = 'demo_chart_age_div';
520
521 ga_charts = {
522
523 init: function (callback) {
524 $(document).ready(function () {
525 google.charts.load('current', {
526 'packages': ['corechart']
527 });
528 ga_loader.show();
529 google.charts.setOnLoadCallback(callback);
530 });
531 },
532 createTooltip: function (day, pageviews) {
533 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
534 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
535 + '</strong>' + '</div>';
536 },
537 events: function (data) {
538 $(window).on('resize', function () {
539 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
540 });
541 },
542 drawChart: function (data, chartWidth) {
543
544 if (typeof chartWidth == 'undefined') {
545 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
546 }
547
548 const options = {
549 /*title : 'Page Views',*/
550 lineWidth: 5,
551 pointSize: 10,
552 tooltip: {
553 isHtml: true
554 },
555 legend: {
556 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
557 : 'top'),
558 maxLines: 5,
559 alignment: 'start',
560 textStyle: {color: '#000', fontSize: 12}
561 },
562 colors: ['#4285f4'],
563 hAxis: {
564 title: 'Day',
565 titleTextStyle: {
566 color: '#333'
567 }
568 },
569 vAxis: {
570 minValue: 0
571 },
572 width: chartWidth,
573 height: 500,
574 chartArea: {
575 top: 50,
576 left: 50,
577 right: 30,
578 bottom: 100
579 },
580 };
581 var chart = new google.visualization.AreaChart(document
582 .getElementById(chartContainer));
583 chart.draw(data, options);
584 },
585 drawDemoGenderChart: function (data, chartWidth) {
586
587 if (typeof chartWidth == 'undefined') {
588 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
589 }
590
591 var data = google.visualization.arrayToDataTable(data);
592
593 var options = {
594 title: 'Gender'
595 };
596
597 var chart = new google.visualization.PieChart(document.getElementById(demoChartGenderContainer));
598
599 chart.draw(data, options);
600 },
601
602 drawDemoAgeChart: function (data, chartWidth) {
603
604 if (typeof chartWidth == 'undefined') {
605 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
606 }
607
608 var data = google.visualization.arrayToDataTable(data);
609
610 var options = {
611 title: 'Age',
612 chartArea: {width: '50%'},
613 hAxis: {
614 minValue: 0
615 },
616 };
617
618 var chart = new google.visualization.BarChart(document.getElementById(demoChartAgeContainer));
619
620 chart.draw(data, options);
621 }
622 };
623 ga_debug = {
624 url: '',
625 open_modal: function (e) {
626 e.preventDefault();
627 $('#' + GA_DEBUG_MODAL_ID).appendTo("body").show();
628 $('#ga-send-debug-email').removeAttr('disabled');
629 $('#ga_debug_error').hide();
630 $('#ga_debug_success').hide();
631 },
632 send_email: function (e) {
633 e.preventDefault();
634 ga_loader.show();
635 var dataObj = {};
636 dataObj['action'] = "googleanalytics_send_debug_email";
637 dataObj['email'] = $('#' + GA_DEBUG_EMAIL).val();
638 dataObj['description'] = $('#' + GA_DEBUG_DESCRIPTION).val();
639 $.ajax({
640 type: "post",
641 dataType: "json",
642 url: ajaxurl,
643 data: dataObj,
644 success: function (response) {
645 ga_loader.hide();
646 if (typeof response.error !== "undefined") {
647 $('#ga_debug_error').show().html(response.error);
648 } else if (typeof response.success !== "undefined"){
649 $('#ga_debug_error').hide();
650 $('#ga-send-debug-email').attr('disabled','disabled');
651 $('#ga_debug_success').show().html(response.success);
652 }
653 }
654 });
655 }
656 };
657 })(jQuery);
658