PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.1.3
ShareThis Dashboard for Google Analytics v2.1.3
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 9 years ago
googleanalytics_page.js
256 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 $('#' + GA_DEBUG_MODAL_CONTENT_ID ).click(function(event){
107 event.stopPropagation();
108 });
109 }
110 };
111
112 /**
113 * Handles "disable all features" switch button
114 * @type {{init: ga_switcher.init}}
115 */
116 ga_switcher = {
117 init: function (state) {
118 var checkbox = $("#ga-disable");
119
120 if (state) {
121 checkbox.prop('checked', 'checked');
122 } else {
123 checkbox.removeProp('checked');
124 }
125
126 $("#ga-slider").on("click", function (e) {
127 var manually_enter_not_checked = $('#ga_enter_code_manually').not(':checked');
128 if (checkbox.not(':checked').length > 0) {
129 if (confirm('This will disable Dashboards, Viral Alerts and Google API')) {
130 setTimeout(function () {
131 window.location.href = GA_DISABLE_FEATURE_URL;
132 }, 350);
133 } else {
134 setTimeout(function () {
135 checkbox.removeProp('checked');
136 }, 350);
137 }
138 } else { // disable
139 setTimeout(function () {
140 window.location.href = GA_ENABLE_FEATURE_URL;
141 }, 350);
142 }
143 });
144 }
145 };
146
147 $(document).ready(function () {
148 ga_events.initModalEvents();
149 });
150
151 const offset = 50;
152 const minWidth = 350;
153 const wrapperSelector = '#ga-stats-container';
154 const chartContainer = 'chart_div';
155
156 ga_charts = {
157
158 init: function (callback) {
159 $(document).ready(function () {
160 google.charts.load('current', {
161 'packages': ['corechart']
162 });
163 ga_loader.show();
164 google.charts.setOnLoadCallback(callback);
165 });
166 },
167 createTooltip: function (day, pageviews) {
168 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
169 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
170 + '</strong>' + '</div>';
171 },
172 events: function (data) {
173 $(window).on('resize', function () {
174 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
175 });
176 },
177 drawChart: function (data, chartWidth) {
178
179 if (typeof chartWidth == 'undefined') {
180 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
181 }
182
183 const options = {
184 /*title : 'Page Views',*/
185 lineWidth: 5,
186 pointSize: 10,
187 tooltip: {
188 isHtml: true
189 },
190 legend: {
191 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
192 : 'top'),
193 maxLines: 5,
194 alignment: 'start',
195 textStyle: {color: '#000', fontSize: 12}
196 },
197 colors: ['#4285f4', '#ff9800'],
198 hAxis: {
199 title: 'Day',
200 titleTextStyle: {
201 color: '#333'
202 }
203 },
204 vAxis: {
205 minValue: 0
206 },
207 width: chartWidth,
208 height: 500,
209 chartArea: {
210 top: 50,
211 left: 50,
212 right: 30,
213 bottom: 100
214 },
215 };
216 var chart = new google.visualization.AreaChart(document
217 .getElementById(chartContainer));
218 chart.draw(data, options);
219 }
220 };
221 ga_debug = {
222 url: '',
223 open_modal: function (e) {
224 e.preventDefault();
225 $('#' + GA_DEBUG_MODAL_ID).appendTo("body").show();
226 $('#ga-send-debug-email').removeAttr('disabled');
227 $('#ga_debug_error').hide();
228 $('#ga_debug_success').hide();
229 },
230 send_email: function (e) {
231 e.preventDefault();
232 ga_loader.show();
233 var dataObj = {};
234 dataObj['action'] = "googleanalytics_send_debug_email";
235 dataObj['email'] = $('#' + GA_DEBUG_EMAIL).val();
236 dataObj['description'] = $('#' + GA_DEBUG_DESCRIPTION).val();
237 $.ajax({
238 type: "post",
239 dataType: "json",
240 url: ajaxurl,
241 data: dataObj,
242 success: function (response) {
243 ga_loader.hide();
244 if (typeof response.error !== "undefined") {
245 $('#ga_debug_error').show().html(response.error);
246 } else if (typeof response.success !== "undefined"){
247 $('#ga_debug_error').hide();
248 $('#ga-send-debug-email').attr('disabled','disabled');
249 $('#ga_debug_success').show().html(response.success);
250 }
251 }
252 });
253 }
254 };
255 })(jQuery);
256