blob: 8ea591fca749df9372d9e00b800a9f49d1ebbf7a (
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
|
/*!
* 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
return Matomo.postEvent(name, ...args);
};
($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);
|