Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sualko/cloud_piwik.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorsualko <klaus@jsxc.org>2015-09-03 17:41:15 +0300
committersualko <klaus@jsxc.org>2015-09-03 17:41:15 +0300
commit9f3b46afd2f129030536ac30f17bc054b37c27d6 (patch)
treea346af07197ced9504f58654db5fd5ac56a8af7b /js
parent813a63762283aad03e832b1cee93e110e83f7df9 (diff)
add admin settings
Diffstat (limited to 'js')
-rw-r--r--js/settings-admin.js42
-rw-r--r--js/track.js74
2 files changed, 88 insertions, 28 deletions
diff --git a/js/settings-admin.js b/js/settings-admin.js
new file mode 100644
index 0000000..c174b30
--- /dev/null
+++ b/js/settings-admin.js
@@ -0,0 +1,42 @@
+/*!
+ * Piwik Tracking
+ *
+ * Copyright (c) 2015 Klaus Herberth <klaus@jsxc.org> <br>
+ * Released under the MIT license
+ *
+ * @author Klaus Herberth <klaus@jsxc.org>
+ * @license MIT
+ */
+
+$(function() {
+ OC.AppConfig.getValue('piwik', 'piwik', {}, function(piwik){
+ piwik = JSON.parse(piwik);
+
+ $('#piwikSiteId').val(piwik.siteId);
+ $('#piwikUrl').val(piwik.url);
+
+ $('#piwikUrl').attr('placeholder', 'e.g. //' + window.location.host + '/piwik/');
+ });
+
+ $('#piwikSettings input[type="text"]').change(function() {
+ var piwik = {}, value;
+
+ piwik.siteId = $('#piwikSiteId').val();
+ piwik.url = $('#piwikUrl').val();
+ piwik.validity = 60*60*24;
+
+ if (!piwik.url.match(/\/$/)) {
+ piwik.url += '/';
+ }
+
+ OC.AppConfig.setValue('piwik', 'piwik', JSON.stringify(piwik));
+ });
+
+ OC.AppConfig.getValue('piwik', 'internal', false, function(internal){
+ $('#piwikInternal').prop('checked', internal === 'yes');
+ });
+
+ $('#piwikInternal').change(function() {
+ OC.AppConfig.setValue('piwik', 'internal', $('#piwikInternal').prop('checked')?'yes':'no');
+ });
+});
diff --git a/js/track.js b/js/track.js
index 8b271a1..0261785 100644
--- a/js/track.js
+++ b/js/track.js
@@ -13,40 +13,58 @@ var _paq = _paq || [];
(function() {
"use strict";
- var url= (typeof localStorage !== 'undefined' && localStorage.getItem('piwik_url'));
- url = url || '//' + window.location.host + '/piwik/';
- var app = null;
- var path = window.location.pathname;
- var pathparts = path.match(/index\.php\/apps\/([a-z0-9]+)\/?/i) || path.match(/index\.php\/([a-z0-9]+)(\/([a-z0-9]+))?/i);
-
- if(pathparts.length >= 2) {
- app = pathparts[1];
-
- if (app === 's') {
- app = 'share';
+ var piwik = (typeof localStorage !== 'undefined') ? OC.localStorage.getItem('piwik') : null;
+
+ if (piwik && (piwik.validUntil || 0) > (new Date()).getTime() / 1000 && !oc_debug) {
+ track(piwik.siteId, piwik.url);
+ } else {
+ OC.AppConfig.getValue('piwik', 'piwik', {}, function(piwik) {
+ piwik = JSON.parse(piwik);
- _paq.push(['setCustomVariable','2','Shares', pathparts[3], 'page']);
- }
-
- _paq.push(['setCustomVariable','1','App', app, 'page']);
- }
+ if (piwik.siteId && piwik.url) {
+ piwik.validUntil = (new Date()).getTime() + (piwik.validity * 1000);
+
+ OC.localStorage.setItem('piwik', piwik);
- if (OC && OC.currentUser) {
- _paq.push(['setUserId', OC.currentUser]);
+ track(piwik.siteId, piwik.url);
+ }
+ });
}
+
+ function track(siteId, url) {
+ var app = null;
+ var path = window.location.pathname;
+ var pathparts = path.match(/index\.php\/apps\/([a-z0-9]+)\/?/i) || path.match(/index\.php\/([a-z0-9]+)(\/([a-z0-9]+))?/i);
- //_paq.push(['setDownloadClasses', ['action-download', 'piwik_download']]);
- // _paq.push(['enableLinkTracking']);
+ if(pathparts.length >= 2) {
+ app = pathparts[1];
+
+ if (app === 's') {
+ app = 'share';
+
+ _paq.push(['setCustomVariable','2','Shares', pathparts[3], 'page']);
+ }
+
+ _paq.push(['setCustomVariable','1','App', app, 'page']);
+ }
+
+ if (OC && OC.currentUser) {
+ _paq.push(['setUserId', OC.currentUser]);
+ }
- _paq.push(['setTrackerUrl', url+'piwik.php']);
- _paq.push(['setSiteId', 1]);
+ //_paq.push(['setDownloadClasses', ['action-download', 'piwik_download']]);
+ // _paq.push(['enableLinkTracking']);
- $(function(){
- _paq.push(['trackPageView']);
- });
+ _paq.push(['setTrackerUrl', url+'piwik.php']);
+ _paq.push(['setSiteId', siteId]);
- if (typeof Piwik === 'undefined') {
- var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=url+'piwik.js'; s.parentNode.insertBefore(g,s);
+ $(function(){
+ _paq.push(['trackPageView']);
+ });
+
+ if (typeof Piwik === 'undefined') {
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=url+'piwik.js'; s.parentNode.insertBefore(g,s);
+ }
}
}());