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

Matomo.adapter.ts « Matomo « src « vue « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0ab71e38efc68f21e29aceb5b6baf133352225cf (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
/*!
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

import { IAngularEvent, IRootScopeService } from 'angular';
import Matomo from './Matomo';

function piwikService() {
  return Matomo;
}

window.angular.module('piwikApp.service').service('piwik', piwikService);

function initPiwikService(piwik: PiwikGlobal, $rootScope: IRootScopeService) {
  // overwrite $rootScope so all events also go through Matomo.postEvent(...) too.
  ($rootScope as any).$oldEmit = $rootScope.$emit; // eslint-disable-line
  $rootScope.$emit = function emitWrapper(name: string, ...args: any[]): IAngularEvent { // eslint-disable-line
    Matomo.postEvent(name, ...args);
    // can't always get the result. it's not really used in angularjs though, so it should be ok.
    return null as unknown as IAngularEvent;
  };

  ($rootScope as any).$oldBroadcast = $rootScope.$broadcast; // eslint-disable-line
  $rootScope.$broadcast = function broadcastWrapper(name: string, ...args: any[]): IAngularEvent { // eslint-disable-line
    Matomo.postEventNoEmit(name, ...args);
    return ($rootScope as any).$oldBroadcast(name, ...args); // eslint-disable-line
  };

  $rootScope.$on('$locationChangeSuccess', piwik.updatePeriodParamsFromUrl);
}

initPiwikService.$inject = ['piwik', '$rootScope'];

window.angular.module('piwikApp.service').run(initPiwikService);