PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.5.5
ShareThis Dashboard for Google Analytics v2.5.5
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 4 years ago googleanalytics_createprop.js 4 years ago googleanalytics_dashboard.js 4 years ago googleanalytics_page.js 4 years ago
googleanalytics_page.js
855 lines
1 /**
2 * Google Analytics Page script.
3 *
4 * @package GoogleAnalytics
5 */
6
7 const GA_ACCESS_CODE_MODAL_ID = "ga_access_code_modal";
8 const GA_DEBUG_MODAL_ID = "ga_debug_modal";
9 const GA_DEBUG_MODAL_CONTENT_ID = "ga_debug_modal_content";
10 const GA_DEBUG_EMAIL = "ga_debug_email";
11 const GA_DEBUG_DESCRIPTION = "ga_debug_description";
12 const GA_ACCESS_CODE_TMP_ID = "ga_access_code_tmp";
13 const GA_ACCESS_CODE_ID = "ga_access_code";
14 const GA_FORM_ID = "ga_form";
15 const GA_MODAL_CLOSE_ID = 'ga_close';
16 const GA_MODAL_BTN_CLOSE_ID = 'ga_btn_close';
17 const GA_GOOGLE_AUTH_BTN_ID = 'ga_authorize_with_google_button';
18 const GA_SAVE_ACCESS_CODE_BTN_ID = 'ga_save_access_code';
19 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.';
20
21 ( function( $ ) {
22 ga_popup = {
23 url: '',
24 authorize: function( e, url ) {
25 e.preventDefault();
26 ga_popup.url = url;
27 $( '#' + GA_ACCESS_CODE_MODAL_ID ).appendTo( "body" ).show();
28 ga_popup.open();
29 },
30 open: function() {
31 const p_width = Math.round( screen.width / 2 );
32 const p_height = Math.round( screen.height / 2 );
33 const p_left = Math.round( p_width / 2 );
34 const p_top = 300;
35 window.open(
36 ga_popup.url,
37 'ga_auth_popup',
38 'width=' + p_width + ',height='
39 + p_height + ',top=' + p_top + ',left=' + p_left,
40 );
41 },
42 saveAccessCode: function( e ) {
43 e.preventDefault();
44 e.target.disabled = 'disabled';
45 ga_loader.show();
46 const ac_tmp = $( '#' + GA_ACCESS_CODE_TMP_ID ).val();
47 if ( ga_popup.validateCode( e, ac_tmp ) ) {
48 $( '#' + GA_ACCESS_CODE_ID ).val( ac_tmp );
49 $( '#' + GA_FORM_ID ).submit();
50 }
51 },
52 validateCode: function( e, code ) {
53 if ( ! code ) {
54 ga_loader.hide();
55 $( '#' + GA_SAVE_ACCESS_CODE_BTN_ID ).removeAttr( 'disabled' );
56 return false;
57 } else if ( code.substring( 0, 2 ) == 'UA' ) {
58 $( '#ga_code_error' ).show().html( GA_AUTHENTICATION_CODE_ERROR );
59 ga_loader.hide();
60 $( '#' + GA_SAVE_ACCESS_CODE_BTN_ID ).removeAttr( 'disabled' );
61 return false;
62 }
63 return true;
64 },
65 };
66
67 ga_modal = {
68 hide: function() {
69 $( '#' + GA_ACCESS_CODE_MODAL_ID ).hide();
70 $( '#' + GA_DEBUG_MODAL_ID ).hide();
71 ga_loader.hide();
72 $( '#' + GA_SAVE_ACCESS_CODE_BTN_ID ).removeAttr( 'disabled' );
73 },
74 };
75
76 ga_events = {
77
78 /**
79 * Send Demographic data.
80 *
81 * @param data
82 */
83 sendDemoData: function( demoData ) {
84 // Send demographic data.
85 $.ajax(
86 {
87 url: 'https://platform-api.sharethis.com/v1.0/property?id=' + ga_property_id + '&secret=' + ga_secret_id,
88 method: 'PUT',
89 async: false,
90 contentType: 'application/json; charset=utf-8',
91 data: JSON.stringify(
92 {
93 "demographics": demoData,
94 },
95 ),
96 },
97 );
98 },
99 /**
100 * Returns gdpr onboarding config values.
101 */
102 setGDPRConfig: function( isGDPR ) {
103
104 /**
105 * Check if ad blocker exists and notify if so.
106 */
107 $( document ).ready(
108 function() {
109 if ( $( "#detectadblock" ).height() > 0 ) {
110 } else {
111 $( '#adblocker-notice' ).show();
112 }
113 },
114 );
115
116 if ( ! isGDPR || undefined === gaGdprConfig ) {
117 return;
118 }
119
120 var config = JSON.parse( gaGdprConfig );
121
122 $( '.gdpr-platform input[name="gdpr-enable"]' ).prop( 'checked', config['enabled'] === 'true' );
123 $( '#sharethis-publisher-name' ).val( config['publisher_name'] );
124 $( '#sharethis-user-type option[value="' + config['display'] + '"]' ).attr( 'selected', true );
125 $( '#sharethis-consent-type option[value="' + config['scope'] + '"]' ).attr( 'selected', true );
126 $( '#sharethis-form-color .color[data-value="' + config['color'] + '"]' ).addClass( 'selected' );
127 $( '#st-language option[value="' + config['language'] + '"]' ).attr( 'selected', true );
128
129 if ( undefined !== config['publisher_purposes'] ) {
130 $( "#publisher-purpose .purpose-item input" ).prop( 'checked', false );
131
132 config['publisher_purposes'].map(
133 ( purpVal ) =>
134 {
135 var legit = 'true' === purpVal['legitimate_interest'] || true === purpVal['legitimate_interest'];
136 var consent = 'false' === purpVal['legitimate_interest'] || false === purpVal['legitimate_interest'];
137
138 $( '#publisher-purpose .purpose-item input[name="purposes[' + purpVal.id + ']"][value="legitimate"]' ).prop( 'checked', legit );
139 $( '#publisher-purpose .purpose-item input[name="purposes[' + purpVal.id + ']"][value="consent"]' ).prop( 'checked', consent );
140 }
141 );
142 }
143
144 if ( undefined !== config['publisher_restrictions'] ) {
145 $( ".vendor-table-cell-wrapper input" ).prop( 'checked', false );
146
147 $.map(
148 config['publisher_restrictions'],
149 function( id, venVal ) {
150 if ( id ) {
151 $( 'input[type="checkbox"][data-id="' + venVal + '"]' ).prop( 'checked', true );
152 }
153 },
154 );
155 }
156 },
157 scrollToAnchor: function( aid ) {
158 var aTag = $( "a[name='" + aid.toLowerCase() + "']" );
159
160 $( '.vendor-table-body' ).animate(
161 {
162 scrollTop: 0,
163 },
164 0,
165 ).animate(
166 {
167 scrollTop: aTag.offset().top - 740,
168 },
169 0,
170 );
171 },
172
173 click: function( selector, callback ) {
174 $( selector ).live( 'click', callback );
175 },
176 codeManuallyCallback: function( features_enabled ) {
177 var checkbox = $( '#ga_enter_code_manually' );
178 if ( features_enabled ) {
179 if ( checkbox.is( ':checked' ) ) {
180 if ( confirm( 'Warning: If you enter your Tracking ID manually, Analytics statistics will not be shown.' ) ) {
181 setTimeout(
182 function() {
183 $( '#ga_authorize_with_google_button' ).attr( 'disabled', 'disabled' ).next().show();
184 $( '#ga_account_selector' ).attr( 'disabled', 'disabled' );
185 $( '#ga_manually_wrapper' ).show();
186 },
187 350,
188 );
189
190 } else {
191 setTimeout(
192 function() {
193 checkbox.removeProp( 'checked' );
194 },
195 350,
196 );
197 }
198 } else {
199 setTimeout(
200 function() {
201 $( '#ga_authorize_with_google_button' ).removeAttr( 'disabled' ).next().hide();
202 $( '#ga_account_selector' ).removeAttr( 'disabled' );
203 $( '#ga_manually_wrapper' ).hide();
204 },
205 350,
206 );
207 }
208 }
209 },
210 initModalEvents: function() {
211 $( 'body' ).on(
212 'click',
213 '#close-review-us',
214 function() {
215 var dataObj = {},
216 self = this;
217 dataObj['action'] = "ga_ajax_hide_review";
218 dataObj[GA_NONCE_FIELD] = GA_NONCE;
219
220 $.ajax(
221 {
222 type: "post",
223 dataType: "json",
224 url: ajaxurl,
225 data: dataObj,
226 success: function( response ) {
227 $( '.ga-review-us' ).fadeOut();
228 },
229 },
230 );
231 },
232 );
233
234 $( '#' + GA_GOOGLE_AUTH_BTN_ID ).on(
235 'click',
236 function() {
237 $( '#' + GA_ACCESS_CODE_TMP_ID ).focus();
238 },
239 );
240
241 $( '#' + GA_MODAL_CLOSE_ID + ', #' + GA_MODAL_BTN_CLOSE_ID + ', #' + GA_DEBUG_MODAL_ID ).on(
242 'click',
243 function() {
244 ga_modal.hide();
245 },
246 );
247
248 $( '#copy-debug' ).on(
249 'click',
250 function() {
251 var copiedText = $( '#ga_debug_info' );
252
253 copiedText.select();
254 document.execCommand( 'copy' );
255 },
256 );
257
258 $( '#' + GA_DEBUG_MODAL_CONTENT_ID ).click(
259 function( event ) {
260 event.stopPropagation();
261 },
262 );
263 },
264
265 getConfig: function() {
266 var config,
267 enabled = $( 'input[name="gdpr-enable"]' ).is( ':checked' ),
268 publisherPurposes = [],
269 display = $( '#sharethis-user-type option:selected' ).val(),
270 name = $( '#sharethis-publisher-name' ).val(),
271 scope = 'publisher',
272 color = $( '#sharethis-form-color .color.selected' ).attr( 'data-value' ),
273 publisherRestrictions = {},
274 language = $( '#st-language' ).val();
275
276 $( '#publisher-purpose input:checked' ).each(
277 function( index, value ) {
278 var theId = $( value ).attr( 'data-id' ),
279 legit = 'consent' !== $( value ).val();
280
281 publisherPurposes.push( { 'id': theId, 'legitimate_interest': legit } );
282 },
283 );
284
285 $( '.vendor-table-cell-wrapper label input:checked' ).each(
286 function( index, value ) {
287 var vendorId = $( value ).attr( 'data-id' );
288 if ( vendorId ) {
289 publisherRestrictions[vendorId] = true;
290 }
291 },
292 );
293
294 config = {
295 enabled: enabled,
296 display: display,
297 publisher_name: name,
298 publisher_purposes: publisherPurposes,
299 publisher_restrictions: publisherRestrictions,
300 language: language,
301 color: color,
302 scope: scope,
303 };
304
305 return config;
306 },
307
308 enableGdpr: function() {
309 var timer = '';
310 this.$gdprContainer = $( '.gdpr-platform' );
311
312 // New color select.
313 this.$gdprContainer.on(
314 'click',
315 "#sharethis-form-color .color",
316 function() {
317 $( '#sharethis-form-color .color' ).removeClass( 'selected' );
318 $( this ).addClass( 'selected' );
319 }
320 );
321
322 // clear or show choices.
323 this.$gdprContainer.on(
324 'click',
325 '#clear-choices',
326 function( e ) {
327 e.preventDefault();
328 e.stopPropagation();
329
330 $( '.purpose-item input' ).prop( 'checked', false );
331 },
332 );
333
334 // clear or show choices.
335 this.$gdprContainer.on(
336 'click',
337 '#see-st-choices',
338 function( e ) {
339 e.preventDefault();
340 e.stopPropagation();
341 $( '.purpose-item input[name="purposes[1]"]' ).prop( 'checked', true );
342 $( '.purpose-item input[name="purposes[3]"][value="consent"]' ).prop( 'checked', true );
343 $( '.purpose-item input[name="purposes[5]"][value="consent"]' ).prop( 'checked', true );
344 $( '.purpose-item input[name="purposes[6]"][value="consent"]' ).prop( 'checked', true );
345 $( '.purpose-item input[name="purposes[9]"][value="legitimate"]' ).prop( 'checked', true );
346 $( '.purpose-item input[name="purposes[10]"][value="legitimate"]' ).prop( 'checked', true );
347 },
348 );
349
350 // Uncheck radio if click on selected box.
351 this.$gdprContainer.on(
352 'click',
353 '.lever',
354 ( e ) =>
355 {
356 e.preventDefault();
357 e.stopPropagation();
358
359 const theInput = $( e.currentTarget ).siblings( 'input' );
360
361 if ( theInput.is( ':checked' ) ) {
362 $( 'input[name="' + theInput.attr( 'name' ) + '"]' ).prop( 'checked', false );
363 } else {
364 theInput.prop( 'checked', true );
365 }
366 },
367 );
368
369 // Toggle button menus when arrows are clicked.
370 $( 'body' ).on(
371 'click',
372 '.accor-wrap .accor-tab',
373 function() {
374 var type = $( this ).find( 'span.accor-arrow' );
375
376 var closestButton = $( type ).parent( '.accor-tab' ).parent( '.accor-wrap' );
377
378 if ( '' === type.html() ) {
379
380 // Show the button configs.
381 closestButton.find( '.accor-content' ).slideDown();
382
383 // Change the icon next to title.
384 closestButton.find( '.accor-arrow' ).html( '&#9660;' );
385 } else {
386
387 // Show the button configs.
388 closestButton.find( '.accor-content' ).slideUp();
389
390 // Change the icon next to title.
391 closestButton.find( '.accor-arrow' ).html( '&#9658;' );
392 }
393 },
394 );
395
396 $( 'body' ).on(
397 'click',
398 '.demo-enable-popup .close-demo-modal',
399 function( e ) {
400 e.preventDefault();
401 e.stopPropagation();
402 $( '.demo-enable-popup' ).removeClass( 'engage' );
403 },
404 );
405
406 $( 'body' ).on(
407 'click',
408 '#demographic-popup',
409 function( e ) {
410 e.preventDefault();
411 e.stopPropagation();
412 $( '.demo-enable-popup' ).addClass( 'engage' );
413 },
414 );
415
416 $( 'body' ).on(
417 'click',
418 '#enable-demographic, #Enable-demographic',
419 function( e ) {
420 e.preventDefault();
421 e.stopPropagation();
422 ga_events.enableDemographic( 'enable' );
423 },
424 );
425
426 $( 'body' ).on(
427 'click',
428 '#Disable-demographic',
429 function( e ) {
430 e.preventDefault();
431 e.stopPropagation();
432 ga_events.enableDemographic( 'disable' );
433 },
434 );
435
436 // Handle account sign-out via Ajax.
437 $( 'body' ).on(
438 'click',
439 '#ga_sign_out',
440 function ( e ) {
441 e.preventDefault();
442 e.stopPropagation();
443
444 $.ajax(
445 {
446 type: 'post',
447 dataType: 'json',
448 url: googleAnalyticsPage.ajaxurl,
449 data: {
450 action: 'ga_ajax_sign_out',
451 nonce: googleAnalyticsPage.nonce,
452 },
453 success: function ( response ) {
454 window.location.href = encodeURI( googleAnalyticsPage.settingsURL )
455 },
456 },
457 );
458 },
459 );
460
461 // Enable GDPR tool.
462 $( 'body' ).on(
463 'click',
464 '.gdpr-submit',
465 function( e ) {
466 e.preventDefault();
467 e.stopPropagation();
468
469 var dataObj = {},
470 self = this,
471 config = ga_events.getConfig();
472
473 theData = JSON.stringify(
474 {
475 'secret': ga_secret_id,
476 'id': ga_property_id,
477 'product': 'gdpr-compliance-tool-v2',
478 'config': config,
479 },
480 );
481
482 // Send new button status value.
483 $.ajax(
484 {
485 url: 'https://platform-api.sharethis.com/v1.0/property/product',
486 method: 'POST',
487 async: false,
488 contentType: 'application/json; charset=utf-8',
489 data: theData,
490 success:
491 function( results ) {
492 },
493 },
494 );
495
496 dataObj['action'] = "ga_ajax_enable_gdpr";
497 dataObj['nonce'] = 'true';
498 dataObj['config'] = config;
499
500 $.ajax(
501 {
502 type: "post",
503 dataType: "json",
504 url: ajaxurl,
505 data: dataObj,
506 success: function( response ) {
507 window.location.reload();
508 },
509 },
510 );
511 },
512 );
513
514 // Enable GDPR tool.
515 $( 'body' ).on(
516 'click',
517 '.gdpr-enable',
518 function( e ) {
519 e.preventDefault();
520 e.stopPropagation();
521
522 var dataObj = {},
523 self = this,
524 config = ga_events.getConfig();
525
526 if ( $( 'body' ).hasClass( 'google-analytics_page_googleanalytics-settings' ) ) {
527 config = {
528 enabled: true,
529 display: 'eu',
530 publisher_name: '',
531 publisher_purposes: [],
532 language: 'en',
533 color: '',
534 scope: 'global',
535 };
536 }
537
538 theData = JSON.stringify(
539 {
540 'secret': ga_secret_id,
541 'id': ga_property_id,
542 'product': 'gdpr-compliance-tool-v2',
543 'config': config,
544 },
545 );
546
547 // Send new button status value.
548 $.ajax(
549 {
550 url: 'https://platform-api.sharethis.com/v1.0/property/product',
551 method: 'POST',
552 async: false,
553 contentType: 'application/json; charset=utf-8',
554 data: theData,
555 success: function( results ) {
556 },
557 },
558 );
559
560 dataObj['action'] = "ga_ajax_enable_gdpr";
561 dataObj['nonce'] = 'true';
562 dataObj['config'] = config;
563
564 $.ajax(
565 {
566 type: "post",
567 dataType: "json",
568 url: ajaxurl,
569 data: dataObj,
570 success: function( response ) {
571 window.location.href = siteAdminUrl + 'admin.php?page=googleanalytics%2Fgdpr';
572 },
573 },
574 );
575 },
576 );
577
578 // Scroll to anchor in vendor list.
579 // Send user input to category search AFTER they stop typing.
580 $( 'body' ).on(
581 'keyup',
582 '.vendor-search input',
583 function( e ) {
584 clearTimeout( timer );
585
586 timer = setTimeout(
587 function() {
588 ga_events.scrollToAnchor( $( this ).val() );
589 }
590 .bind( this, ga_events ),
591 500,
592 );
593 },
594 );
595 },
596
597 enableDemographic: function( disable ) {
598 var dataObj = {};
599
600 dataObj['action'] = "ga_ajax_enable_demographic";
601 dataObj['nonce'] = ga_demo_nonce;
602 dataObj['enabled'] = 'disable' === disable ? 'false' : 'true';
603
604 $.ajax(
605 {
606 type: "post",
607 dataType: "json",
608 url: ajaxurl,
609 data: dataObj,
610 success: function( response ) {
611 window.location.href = siteAdminUrl + 'admin.php?page=googleanalytics&ga_action=demo-ad';
612 },
613 },
614 );
615 },
616 };
617
618 /**
619 * Handles "disable all features" switch button
620 *
621 * @type {{init: ga_switcher.init}}
622 */
623 ga_switcher = {
624 init: function( state ) {
625 var checkbox = $( "#ga-disable" );
626
627 if ( state ) {
628 checkbox.prop( 'checked', 'checked' );
629 } else {
630 checkbox.removeProp( 'checked' );
631 }
632
633 $( ".ga-slider-disable" ).on(
634 "click",
635 function( e ) {
636 var manually_enter_not_checked = $( '#ga_enter_code_manually' ).not( ':checked' );
637 if ( checkbox.not( ':checked' ).length > 0 ) {
638 if ( confirm( 'This will disable Dashboards and Google API' ) ) {
639 setTimeout(
640 function() {
641 window.location.href = GA_DISABLE_FEATURE_URL;
642 },
643 350,
644 );
645 } else {
646 setTimeout(
647 function() {
648 checkbox.removeProp( 'checked' );
649 },
650 350,
651 );
652 }
653 } else {
654 setTimeout(
655 function() {
656 window.location.href = GA_ENABLE_FEATURE_URL;
657 },
658 350,
659 );
660 }
661 },
662 );
663 },
664 };
665
666 $( document ).ready(
667 function() {
668 const scrollData = $( '#ga-stats-container' ).attr( 'data-scroll' );
669 const scrollEl = '' !== scrollData ? $( '.' + scrollData ) : '';
670 const theBody = $( 'body' );
671
672 ga_events.initModalEvents();
673 ga_events.enableGdpr();
674 ga_events.setGDPRConfig( theBody.hasClass( 'google-analytics_page_googleanalytics-gdpr' ) );
675
676 if ( '' !== scrollData && theBody.hasClass( 'toplevel_page_googleanalytics' ) ) {
677 $( [ document.documentElement, document.body ] ).animate(
678 {
679 scrollTop: scrollEl.offset().top + 450,
680 },
681 500,
682 );
683 }
684 },
685 );
686
687 const offset = 50;
688 const minWidth = 350;
689 const wrapperSelector = '#ga-stats-container';
690 const chartContainer = 'chart_div';
691 const demoChartDeviceContainer = 'demo_chart_device_div';
692 const demoChartGenderContainer = 'demo_chart_gender_div';
693 const demoChartAgeContainer = 'demo_chart_age_div';
694
695 ga_charts = {
696 init: function( callback ) {
697 $( document ).ready(
698 function() {
699 google.charts.load(
700 'current',
701 {
702 'packages': [ 'corechart' ],
703 },
704 );
705 ga_loader.show();
706 google.charts.setOnLoadCallback( callback );
707 },
708 );
709 },
710 createTooltip: function( day, pageviews ) {
711 return '<div style="padding:10px;width:100px;"><strong>' + day
712 + '</strong><br>Pageviews:<strong> ' + pageviews
713 + '</strong></div>';
714 },
715 events: function( data ) {
716 $( window ).on(
717 'resize',
718 function() {
719 ga_charts.drawChart( data, ga_tools.recomputeChartWidth( minWidth, offset, wrapperSelector ) );
720 },
721 );
722 },
723 drawChart: function( data, chartWidth ) {
724
725 if ( typeof chartWidth == 'undefined' ) {
726 chartWidth = ga_tools.recomputeChartWidth( minWidth, offset, wrapperSelector );
727 }
728
729 const options = {
730 lineWidth: 5,
731 pointSize: 10,
732 tooltip: {
733 isHtml: true,
734 },
735 legend: {
736 position: ( ga_tools.getCurrentWidth( wrapperSelector ) <= minWidth ? 'top' : 'top' ),
737 maxLines: 5,
738 alignment: 'start',
739 textStyle: {
740 color: '#000',
741 fontSize: 12,
742 },
743 },
744 colors: [ '#4285f4' ],
745 hAxis: {
746 title: 'Day',
747 titleTextStyle: {
748 color: '#333',
749 },
750 },
751 vAxis: {
752 minValue: 0,
753 },
754 width: chartWidth,
755 height: 500,
756 chartArea: {
757 top: 50,
758 left: 50,
759 right: 30,
760 bottom: 100,
761 },
762 };
763
764 var chart = new google.visualization.AreaChart(
765 document.getElementById( chartContainer )
766 );
767 chart.draw( data, options );
768 },
769 drawDemoGenderChart: function( data, chartWidth ) {
770 if ( typeof chartWidth == 'undefined' ) {
771 chartWidth = ga_tools.recomputeChartWidth( minWidth, offset, wrapperSelector );
772 }
773
774 data = google.visualization.arrayToDataTable( data );
775
776 var chart = new google.visualization.PieChart( document.getElementById( demoChartGenderContainer ) );
777 var options = {
778 title: 'Gender',
779 };
780
781 chart.draw( data, options );
782 },
783 drawDemoDeviceChart: function( data, chartWidth ) {
784 if ( typeof chartWidth == 'undefined' ) {
785 chartWidth = ga_tools.recomputeChartWidth( minWidth, offset, wrapperSelector );
786 }
787
788 data = google.visualization.arrayToDataTable( data );
789
790 var chart = new google.visualization.PieChart( document.getElementById( demoChartDeviceContainer ) );
791 var options = {
792 title: 'Device Breakdown',
793 };
794
795 chart.draw( data, options );
796 },
797
798 drawDemoAgeChart: function( data, chartWidth ) {
799 if ( typeof chartWidth == 'undefined' ) {
800 chartWidth = ga_tools.recomputeChartWidth( minWidth, offset, wrapperSelector );
801 }
802
803 data = google.visualization.arrayToDataTable( data );
804
805 var options = {
806 title: 'Age',
807 chartArea: { width: '50%' },
808 hAxis: {
809 minValue: 0,
810 },
811 };
812
813 var chart = new google.visualization.BarChart( document.getElementById( demoChartAgeContainer ) );
814
815 chart.draw( data, options );
816 },
817 };
818 ga_debug = {
819 url: '',
820 open_modal: function( e ) {
821 e.preventDefault();
822 $( '#' + GA_DEBUG_MODAL_ID ).appendTo( "body" ).show();
823 $( '#ga-send-debug-email' ).removeAttr( 'disabled' );
824 $( '#ga_debug_error' ).hide();
825 $( '#ga_debug_success' ).hide();
826 },
827 send_email: function( e ) {
828 e.preventDefault();
829 ga_loader.show();
830 var dataObj = {};
831 dataObj['action'] = "googleanalytics_send_debug_email";
832 dataObj['email'] = $( '#' + GA_DEBUG_EMAIL ).val();
833 dataObj['description'] = $( '#' + GA_DEBUG_DESCRIPTION ).val();
834 $.ajax(
835 {
836 type: "post",
837 dataType: "json",
838 url: ajaxurl,
839 data: dataObj,
840 success: function( response ) {
841 ga_loader.hide();
842 if ( typeof response.error !== "undefined" ) {
843 $( '#ga_debug_error' ).show().html( response.error );
844 } else if ( typeof response.success !== "undefined" ) {
845 $( '#ga_debug_error' ).hide();
846 $( '#ga-send-debug-email' ).attr( 'disabled', 'disabled' );
847 $( '#ga_debug_success' ).show().html( response.success );
848 }
849 },
850 },
851 );
852 },
853 };
854 } )( jQuery );
855