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

track.js « js « build - github.com/sualko/cloud_piwik.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94a18ca754ccc914ff000f2f9b31bd1d8d17b792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*!
 * cloud_piwik v0.5.0 - 2018-10-29
 * 
 * Copyright (c) 2018 Klaus Herberth <klaus@jsxc.org> <br>
 * Released under the MIT license
 * 
 * Please see https://github.com/sualko/cloud_piwik
 * 
 * @author Klaus Herberth <klaus@jsxc.org>
 * @version 0.5.0
 * @license MIT
 */

/* global OC */

var _paq = _paq || [];

(function() {
   "use strict";

   var options;

   try {
      options = JSON.parse('%OPTIONS%');
   } catch (err) {}

   if (!options || !options.url || !options.siteId) {
      return;
   }

   if (options.url[options.url.length - 1] !== '/') {
      options.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) || [];

   if (pathParts.length >= 2) {
      app = pathParts[1];

      if (app === 's') {
         // rewrite app name
         app = 'share';

         var shareValue = $('input[name="filename"]').val();

         if (shareValue) {
            shareValue = pathParts[3] + ' (' + shareValue + ')';

            // save share id + share name in slot 3
            _paq.push(['setCustomVariable', '3', 'ShareNodes', shareValue, 'page']);
         } else {
            shareValue = pathParts[3];
         }

         // save share id in slot 2
         _paq.push(['setCustomVariable', '2', 'Shares', pathParts[3], 'page']);
      }

      // save app name in slot 1
      _paq.push(['setCustomVariable', '1', 'App', app, 'page']);
   }

   if (OC && OC.currentUser && options.trackUser) {
      // set user id
      _paq.push(['setUserId', OC.currentUser]);
   }

   if (options.trackDir === 'on' || options.trackDir === true) {
      // track file browsing

      $('#app-content').delegate('>div', 'afterChangeDirectory', function() {
         // update title and url for next page view
         _paq.push(['setDocumentTitle', document.title]);
         _paq.push(['setCustomUrl', window.location.href]);
         _paq.push(['trackPageView']);
      });
   }

   // set piwik options
   _paq.push(['setTrackerUrl', options.url + 'piwik.php']);
   _paq.push(['setSiteId', options.siteId]);

   if (app !== 'files' || options.trackDir !== 'on') {
      // track page view
      _paq.push(['trackPageView']);
   }

   if (typeof Piwik === 'undefined') {
      // load piwik library
      var d = document,
         g = d.createElement('script'),
         s = d.getElementsByTagName('script')[0];
      g.type = 'text/javascript';
      g.async = true;
      g.defer = true;
      g.src = options.url + 'piwik.js';
      s.parentNode.insertBefore(g, s);
   }
}());