PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.5.0
ShareThis Dashboard for Google Analytics v2.5.0
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
665 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.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 demoChartGenderContainer = 'demo_chart_gender_div';
529 const demoChartAgeContainer = 'demo_chart_age_div';
530
531 ga_charts = {
532
533 init: function (callback) {
534 $(document).ready(function () {
535 google.charts.load('current', {
536 'packages': ['corechart']
537 });
538 ga_loader.show();
539 google.charts.setOnLoadCallback(callback);
540 });
541 },
542 createTooltip: function (day, pageviews) {
543 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
544 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
545 + '</strong>' + '</div>';
546 },
547 events: function (data) {
548 $(window).on('resize', function () {
549 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
550 });
551 },
552 drawChart: function (data, chartWidth) {
553
554 if (typeof chartWidth == 'undefined') {
555 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
556 }
557
558 const options = {
559 /*title : 'Page Views',*/
560 lineWidth: 5,
561 pointSize: 10,
562 tooltip: {
563 isHtml: true
564 },
565 legend: {
566 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
567 : 'top'),
568 maxLines: 5,
569 alignment: 'start',
570 textStyle: {color: '#000', fontSize: 12}
571 },
572 colors: ['#4285f4'],
573 hAxis: {
574 title: 'Day',
575 titleTextStyle: {
576 color: '#333'
577 }
578 },
579 vAxis: {
580 minValue: 0
581 },
582 width: chartWidth,
583 height: 500,
584 chartArea: {
585 top: 50,
586 left: 50,
587 right: 30,
588 bottom: 100
589 },
590 };
591 var chart = new google.visualization.AreaChart(document
592 .getElementById(chartContainer));
593 chart.draw(data, options);
594 },
595 drawDemoGenderChart: function (data, chartWidth) {
596 if (typeof chartWidth == 'undefined') {
597 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
598 }
599
600 data = google.visualization.arrayToDataTable(data);
601
602 var chart = new google.visualization.PieChart(document.getElementById(demoChartGenderContainer));
603 var options = {
604 title: 'Gender'
605 };
606
607 chart.draw(data, options);
608 },
609
610 drawDemoAgeChart: 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 options = {
618 title: 'Age',
619 chartArea: {width: '50%'},
620 hAxis: {
621 minValue: 0
622 },
623 };
624
625 var chart = new google.visualization.BarChart(document.getElementById(demoChartAgeContainer));
626
627 chart.draw(data, options);
628 }
629 };
630 ga_debug = {
631 url: '',
632 open_modal: function (e) {
633 e.preventDefault();
634 $('#' + GA_DEBUG_MODAL_ID).appendTo("body").show();
635 $('#ga-send-debug-email').removeAttr('disabled');
636 $('#ga_debug_error').hide();
637 $('#ga_debug_success').hide();
638 },
639 send_email: function (e) {
640 e.preventDefault();
641 ga_loader.show();
642 var dataObj = {};
643 dataObj['action'] = "googleanalytics_send_debug_email";
644 dataObj['email'] = $('#' + GA_DEBUG_EMAIL).val();
645 dataObj['description'] = $('#' + GA_DEBUG_DESCRIPTION).val();
646 $.ajax({
647 type: "post",
648 dataType: "json",
649 url: ajaxurl,
650 data: dataObj,
651 success: function (response) {
652 ga_loader.hide();
653 if (typeof response.error !== "undefined") {
654 $('#ga_debug_error').show().html(response.error);
655 } else if (typeof response.success !== "undefined"){
656 $('#ga_debug_error').hide();
657 $('#ga-send-debug-email').attr('disabled','disabled');
658 $('#ga_debug_success').show().html(response.success);
659 }
660 }
661 });
662 }
663 };
664 })(jQuery);
665