PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.1.5
ShareThis Dashboard for Google Analytics v2.1.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 9 years ago googleanalytics_dashboard.js 9 years ago googleanalytics_page.js 7 years ago
googleanalytics_page.js
264 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
17 ga_popup = {
18 url: '',
19 authorize: function (e, url) {
20 e.preventDefault();
21 ga_popup.url = url;
22 $('#' + GA_ACCESS_CODE_MODAL_ID).appendTo("body").show();
23 ga_popup.open();
24 },
25 open: function () {
26 const p_width = Math.round(screen.width / 2);
27 const p_height = Math.round(screen.height / 2);
28 const p_left = Math.round(p_width / 2);
29 const p_top = 300;
30 window.open(ga_popup.url, 'ga_auth_popup', 'width=' + p_width + ',height='
31 + p_height + ',top=' + p_top + ',left=' + p_left);
32 },
33 saveAccessCode: function (e) {
34 e.preventDefault();
35 e.target.disabled = 'disabled';
36 ga_loader.show();
37 const ac_tmp = $('#' + GA_ACCESS_CODE_TMP_ID).val();
38 if (ga_popup.validateCode(e, ac_tmp)) {
39 $('#' + GA_ACCESS_CODE_ID).val(ac_tmp);
40 $('#' + GA_FORM_ID).submit();
41 }
42 },
43 validateCode: function (e, code) {
44 if (!code){
45 ga_loader.hide();
46 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
47 return false;
48 }
49 else if (code.substring(0, 2) == 'UA'){
50 $('#ga_code_error').show().html(GA_AUTHENTICATION_CODE_ERROR);
51 ga_loader.hide();
52 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
53 return false;
54 }
55 return true;
56 }
57 };
58
59 ga_modal = {
60 hide: function () {
61 $('#' + GA_ACCESS_CODE_MODAL_ID).hide();
62 $('#' + GA_DEBUG_MODAL_ID).hide();
63 ga_loader.hide();
64 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
65 }
66 };
67
68 ga_events = {
69
70 click: function (selector, callback) {
71 $(selector).live('click', callback);
72 },
73 codeManuallyCallback: function (features_enabled) {
74 var checkbox = $('#ga_enter_code_manually');
75 if ( features_enabled ) {
76 if ( checkbox.is(':checked') ) {
77 if (confirm('Warning: If you enter your Tracking ID manually, Analytics statistics will not be shown.')) {
78 setTimeout(function () {
79 $('#ga_authorize_with_google_button').attr('disabled','disabled').next().show();
80 $('#ga_account_selector').attr('disabled', 'disabled');
81 $('#ga_manually_wrapper').show();
82 }, 350);
83
84 } else {
85 setTimeout(function () {
86 checkbox.removeProp('checked');
87 }, 350);
88 }
89 } else { // disable
90 setTimeout(function () {
91 $('#ga_authorize_with_google_button').removeAttr('disabled').next().hide();
92 $('#ga_account_selector').removeAttr('disabled');
93 $('#ga_manually_wrapper').hide();
94 }, 350);
95 }
96 }
97 },
98 initModalEvents: function () {
99 $('#' + GA_GOOGLE_AUTH_BTN_ID).on('click', function () {
100 $('#' + GA_ACCESS_CODE_TMP_ID).focus();
101 });
102
103 $('#' + GA_MODAL_CLOSE_ID + ', #' + GA_MODAL_BTN_CLOSE_ID + ', #' + GA_DEBUG_MODAL_ID ).on('click', function () {
104 ga_modal.hide();
105 });
106
107 $( '#copy-debug' ).on( 'click', function() {
108 var copiedText = $( '#ga_debug_info' );
109
110 copiedText.select();
111 document.execCommand( 'copy' );
112 } );
113
114 $('#' + GA_DEBUG_MODAL_CONTENT_ID ).click(function(event){
115 event.stopPropagation();
116 });
117 }
118 };
119
120 /**
121 * Handles "disable all features" switch button
122 * @type {{init: ga_switcher.init}}
123 */
124 ga_switcher = {
125 init: function (state) {
126 var checkbox = $("#ga-disable");
127
128 if (state) {
129 checkbox.prop('checked', 'checked');
130 } else {
131 checkbox.removeProp('checked');
132 }
133
134 $(".ga-slider-disable").on("click", function (e) {
135 var manually_enter_not_checked = $('#ga_enter_code_manually').not(':checked');
136 if (checkbox.not(':checked').length > 0) {
137 if (confirm('This will disable Dashboards, Viral Alerts and Google API')) {
138 setTimeout(function () {
139 window.location.href = GA_DISABLE_FEATURE_URL;
140 }, 350);
141 } else {
142 setTimeout(function () {
143 checkbox.removeProp('checked');
144 }, 350);
145 }
146 } else { // disable
147 setTimeout(function () {
148 window.location.href = GA_ENABLE_FEATURE_URL;
149 }, 350);
150 }
151 });
152 }
153 };
154
155 $(document).ready(function () {
156 ga_events.initModalEvents();
157 });
158
159 const offset = 50;
160 const minWidth = 350;
161 const wrapperSelector = '#ga-stats-container';
162 const chartContainer = 'chart_div';
163
164 ga_charts = {
165
166 init: function (callback) {
167 $(document).ready(function () {
168 google.charts.load('current', {
169 'packages': ['corechart']
170 });
171 ga_loader.show();
172 google.charts.setOnLoadCallback(callback);
173 });
174 },
175 createTooltip: function (day, pageviews) {
176 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
177 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
178 + '</strong>' + '</div>';
179 },
180 events: function (data) {
181 $(window).on('resize', function () {
182 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
183 });
184 },
185 drawChart: function (data, chartWidth) {
186
187 if (typeof chartWidth == 'undefined') {
188 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
189 }
190
191 const options = {
192 /*title : 'Page Views',*/
193 lineWidth: 5,
194 pointSize: 10,
195 tooltip: {
196 isHtml: true
197 },
198 legend: {
199 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
200 : 'top'),
201 maxLines: 5,
202 alignment: 'start',
203 textStyle: {color: '#000', fontSize: 12}
204 },
205 colors: ['#4285f4', '#ff9800'],
206 hAxis: {
207 title: 'Day',
208 titleTextStyle: {
209 color: '#333'
210 }
211 },
212 vAxis: {
213 minValue: 0
214 },
215 width: chartWidth,
216 height: 500,
217 chartArea: {
218 top: 50,
219 left: 50,
220 right: 30,
221 bottom: 100
222 },
223 };
224 var chart = new google.visualization.AreaChart(document
225 .getElementById(chartContainer));
226 chart.draw(data, options);
227 }
228 };
229 ga_debug = {
230 url: '',
231 open_modal: function (e) {
232 e.preventDefault();
233 $('#' + GA_DEBUG_MODAL_ID).appendTo("body").show();
234 $('#ga-send-debug-email').removeAttr('disabled');
235 $('#ga_debug_error').hide();
236 $('#ga_debug_success').hide();
237 },
238 send_email: function (e) {
239 e.preventDefault();
240 ga_loader.show();
241 var dataObj = {};
242 dataObj['action'] = "googleanalytics_send_debug_email";
243 dataObj['email'] = $('#' + GA_DEBUG_EMAIL).val();
244 dataObj['description'] = $('#' + GA_DEBUG_DESCRIPTION).val();
245 $.ajax({
246 type: "post",
247 dataType: "json",
248 url: ajaxurl,
249 data: dataObj,
250 success: function (response) {
251 ga_loader.hide();
252 if (typeof response.error !== "undefined") {
253 $('#ga_debug_error').show().html(response.error);
254 } else if (typeof response.success !== "undefined"){
255 $('#ga_debug_error').hide();
256 $('#ga-send-debug-email').attr('disabled','disabled');
257 $('#ga_debug_success').show().html(response.success);
258 }
259 }
260 });
261 }
262 };
263 })(jQuery);
264