PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.0.5
ShareThis Dashboard for Google Analytics v2.0.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 9 years ago
googleanalytics_page.js
159 lines
1 const GA_ACCESS_CODE_MODAL_ID = "ga_access_code_modal";
2 const GA_ACCESS_CODE_TMP_ID = "ga_access_code_tmp";
3 const GA_ACCESS_CODE_ID = "ga_access_code";
4 const GA_FORM_ID = "ga_form";
5 const GA_MODAL_CLOSE_ID = 'ga_close';
6 const GA_MODAL_BTN_CLOSE_ID = 'ga_btn_close';
7 const GA_GOOGLE_AUTH_BTN_ID = 'ga_authorize_with_google_button';
8 const GA_SAVE_ACCESS_CODE_BTN_ID = 'ga_save_access_code';
9
10 (function ($) {
11
12 ga_popup = {
13 url: '',
14 authorize: function (e, url) {
15 e.preventDefault();
16 ga_popup.url = url;
17 $('#' + GA_ACCESS_CODE_MODAL_ID).appendTo("body").show();
18 ga_popup.open();
19 },
20 open: function () {
21 const p_width = Math.round(screen.width / 2);
22 const p_height = Math.round(screen.height / 2);
23 const p_left = Math.round(p_width / 2);
24 const p_top = 300;
25 window.open(ga_popup.url, 'ga_auth_popup', 'width=' + p_width + ',height='
26 + p_height + ',top=' + p_top + ',left=' + p_left);
27 },
28 saveAccessCode: function (e) {
29 e.preventDefault();
30 e.target.disabled = 'disabled';
31 ga_loader.show();
32 const ac_tmp = $('#' + GA_ACCESS_CODE_TMP_ID).val();
33 if (ac_tmp) {
34 $('#' + GA_ACCESS_CODE_ID).val(ac_tmp);
35 $('#' + GA_FORM_ID).submit();
36 }
37 }
38 };
39
40 ga_modal = {
41 hide: function () {
42 $('#' + GA_ACCESS_CODE_MODAL_ID).hide();
43 ga_loader.hide();
44 $('#' + GA_SAVE_ACCESS_CODE_BTN_ID).removeAttr('disabled');
45 }
46 };
47
48 ga_events = {
49
50 click: function (selector, callback) {
51 $(selector).live('click', callback);
52 },
53 codeManuallyCallback: function (terms_accepted) {
54 const button_disabled = $('#ga_authorize_with_google_button').attr('disabled');
55 const selector_disabled = $('#ga_account_selector').attr('disabled');
56 if (terms_accepted) {
57 if (button_disabled) {
58 $('#ga_authorize_with_google_button').removeAttr('disabled').next().hide();
59 } else {
60 $('#ga_authorize_with_google_button').attr('disabled',
61 'disabled').next().show();
62 }
63
64 if (selector_disabled) {
65 $('#ga_account_selector').removeAttr('disabled');
66 } else {
67 $('#ga_account_selector').attr('disabled', 'disabled');
68 }
69 }
70
71 $('#ga_manually_wrapper').toggle();
72 },
73 initModalEvents: function () {
74 $('#' + GA_GOOGLE_AUTH_BTN_ID).on('click', function () {
75 $('#' + GA_ACCESS_CODE_TMP_ID).focus();
76 });
77
78 $('#' + GA_MODAL_CLOSE_ID + ', #' + GA_MODAL_BTN_CLOSE_ID).on('click', function () {
79 ga_modal.hide();
80 });
81 }
82 };
83
84 $(document).ready(function () {
85 ga_events.initModalEvents();
86 });
87
88 const offset = 50;
89 const minWidth = 350;
90 const wrapperSelector = '#ga-stats-container';
91 const chartContainer = 'chart_div';
92
93 ga_charts = {
94
95 init: function (callback) {
96 $(document).ready(function () {
97 google.charts.load('current', {
98 'packages': ['corechart']
99 });
100 ga_loader.show();
101 google.charts.setOnLoadCallback(callback);
102 });
103 },
104 createTooltip: function (day, pageviews) {
105 return '<div style="padding:10px;width:100px;">' + '<strong>' + day
106 + '</strong><br>' + 'Pageviews:<strong> ' + pageviews
107 + '</strong>' + '</div>';
108 },
109 events: function (data) {
110 $(window).on('resize', function () {
111 ga_charts.drawChart(data, ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
112 });
113 },
114 drawChart: function (data, chartWidth) {
115
116 if (typeof chartWidth == 'undefined') {
117 chartWidth = ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector);
118 }
119
120 const options = {
121 /*title : 'Page Views',*/
122 lineWidth: 5,
123 pointSize: 10,
124 tooltip: {
125 isHtml: true
126 },
127 legend: {
128 position: (ga_tools.getCurrentWidth(wrapperSelector) <= minWidth ? 'top'
129 : 'top'),
130 maxLines: 5,
131 alignment: 'start',
132 textStyle: {color: '#000', fontSize: 12}
133 },
134 colors: ['#4285f4', '#ff9800'],
135 hAxis: {
136 title: 'Day',
137 titleTextStyle: {
138 color: '#333'
139 }
140 },
141 vAxis: {
142 minValue: 0
143 },
144 width: chartWidth,
145 height: 500,
146 chartArea: {
147 top: 50,
148 left: 50,
149 right: 30,
150 bottom: 100
151 },
152 };
153 var chart = new google.visualization.AreaChart(document
154 .getElementById(chartContainer));
155 chart.draw(data, options);
156 }
157 };
158 })(jQuery);
159