PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.5.2
ShareThis Dashboard for Google Analytics v2.5.2
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 6 years ago googleanalytics_dashboard.js 9 years ago googleanalytics_page.js 4 years ago
googleanalytics_page.js
680 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 = 'publisher',
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.href = siteAdminUrl + 'admin.php?page=googleanalytics&ga_action=demo-ad';
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 const scrollData = $( '#ga-stats-container' ).attr( 'data-scroll' );
510 const scrollEl = '' !== scrollData ? $('.' + scrollData) : '';
511 const theBody = $('body');
512
513 ga_events.initModalEvents();
514 ga_events.enableGdpr();
515 ga_events.setGDPRConfig(theBody.hasClass('google-analytics_page_googleanalytics-gdpr'));
516
517 if ( '' !== scrollData && theBody.hasClass( 'toplevel_page_googleanalytics' ) ) {
518 $([document.documentElement, document.body]).animate({
519 scrollTop: scrollEl.offset().top + 450
520 }, 500);
521 }
522 });
523
524 const offset = 50;
525 const minWidth = 350;
526 const wrapperSelector = '#ga-stats-container';
527 const chartContainer = 'chart_div';
528 const demoChartDeviceContainer = 'demo_chart_device_div';
529 const demoChartGenderContainer = 'demo_chart_gender_div';
530 const demoChartAgeContainer = 'demo_chart_age_div';
531
532 ga_charts = {
533
534 init: function (callback) {
535 $(document).ready(function () {
536 google.charts.load('current', {
537 'packages': ['corechart']
538 });
539 ga_loader.show();
540 google.charts.setOnLoadCallback(callback);
541 });
542 },
543 createTooltip: function (day, pageviews) {
544 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
545 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
546 + '</strong>' + '</div>';
547 },
548 events: function (data) {
549 $(window).on('resize', function () {
550 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
551 });
552 },
553 drawChart: function (data, chartWidth) {
554
555 if (typeof chartWidth == 'undefined') {
556 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
557 }
558
559 const options = {
560 /*title : 'Page Views',*/
561 lineWidth: 5,
562 pointSize: 10,
563 tooltip: {
564 isHtml: true
565 },
566 legend: {
567 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
568 : 'top'),
569 maxLines: 5,
570 alignment: 'start',
571 textStyle: {color: '#000', fontSize: 12}
572 },
573 colors: ['#4285f4'],
574 hAxis: {
575 title: 'Day',
576 titleTextStyle: {
577 color: '#333'
578 }
579 },
580 vAxis: {
581 minValue: 0
582 },
583 width: chartWidth,
584 height: 500,
585 chartArea: {
586 top: 50,
587 left: 50,
588 right: 30,
589 bottom: 100
590 },
591 };
592 var chart = new google.visualization.AreaChart(document
593 .getElementById(chartContainer));
594 chart.draw(data, options);
595 },
596 drawDemoGenderChart: function (data, chartWidth) {
597 if (typeof chartWidth == 'undefined') {
598 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
599 }
600
601 data = google.visualization.arrayToDataTable(data);
602
603 var chart = new google.visualization.PieChart(document.getElementById(demoChartGenderContainer));
604 var options = {
605 title: 'Gender'
606 };
607
608 chart.draw(data, options);
609 },
610 drawDemoDeviceChart: function (data, chartWidth) {
611 if (typeof chartWidth == 'undefined') {
612 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
613 }
614
615 data = google.visualization.arrayToDataTable(data);
616
617 var chart = new google.visualization.PieChart(document.getElementById(demoChartDeviceContainer));
618 var options = {
619 title: 'Device Breakdown'
620 };
621
622 chart.draw(data, options);
623 },
624
625 drawDemoAgeChart: function (data, chartWidth) {
626 if (typeof chartWidth == 'undefined') {
627 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
628 }
629
630 data = google.visualization.arrayToDataTable(data);
631
632 var options = {
633 title: 'Age',
634 chartArea: {width: '50%'},
635 hAxis: {
636 minValue: 0
637 },
638 };
639
640 var chart = new google.visualization.BarChart(document.getElementById(demoChartAgeContainer));
641
642 chart.draw(data, options);
643 }
644 };
645 ga_debug = {
646 url: '',
647 open_modal: function (e) {
648 e.preventDefault();
649 $('#' + GA_DEBUG_MODAL_ID).appendTo("body").show();
650 $('#ga-send-debug-email').removeAttr('disabled');
651 $('#ga_debug_error').hide();
652 $('#ga_debug_success').hide();
653 },
654 send_email: function (e) {
655 e.preventDefault();
656 ga_loader.show();
657 var dataObj = {};
658 dataObj['action'] = "googleanalytics_send_debug_email";
659 dataObj['email'] = $('#' + GA_DEBUG_EMAIL).val();
660 dataObj['description'] = $('#' + GA_DEBUG_DESCRIPTION).val();
661 $.ajax({
662 type: "post",
663 dataType: "json",
664 url: ajaxurl,
665 data: dataObj,
666 success: function (response) {
667 ga_loader.hide();
668 if (typeof response.error !== "undefined") {
669 $('#ga_debug_error').show().html(response.error);
670 } else if (typeof response.success !== "undefined"){
671 $('#ga_debug_error').hide();
672 $('#ga-send-debug-email').attr('disabled','disabled');
673 $('#ga_debug_success').show().html(response.success);
674 }
675 }
676 });
677 }
678 };
679 })(jQuery);
680