2021-08-10 22:45:53 +00:00
|
|
|
import angular from 'angular';
|
2022-01-03 15:49:59 +00:00
|
|
|
import { setPortainerStatus, setUserRole, clearUserRole, setUserEndpointRole, clearUserEndpointRole, push, trackEvent } from './analytics-services';
|
2021-08-10 22:45:53 +00:00
|
|
|
const basePath = 'http://portainer-ce.app';
|
|
|
|
|
|
|
|
// forked from https://github.com/angulartics/angulartics-piwik/blob/master/src/angulartics-piwik.js
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngdoc overview
|
|
|
|
* @name angulartics.piwik
|
|
|
|
* Enables analytics support for Piwik/Matomo (http://piwik.org/docs/tracking-api/)
|
|
|
|
*/
|
|
|
|
export default angular.module('angulartics.matomo', ['angulartics']).config(config).name;
|
|
|
|
|
|
|
|
/* @ngInject */
|
|
|
|
function config($analyticsProvider, $windowProvider) {
|
|
|
|
const $window = $windowProvider.$get();
|
|
|
|
|
|
|
|
$analyticsProvider.settings.pageTracking.trackRelativePath = true;
|
|
|
|
|
|
|
|
$analyticsProvider.api.setPortainerStatus = setPortainerStatus;
|
|
|
|
|
|
|
|
$analyticsProvider.api.setUserRole = setUserRole;
|
|
|
|
$analyticsProvider.api.clearUserRole = clearUserRole;
|
|
|
|
|
|
|
|
$analyticsProvider.api.setUserEndpointRole = setUserEndpointRole;
|
|
|
|
$analyticsProvider.api.clearUserEndpointRole = clearUserEndpointRole;
|
|
|
|
|
|
|
|
// scope: visit or page. Defaults to 'page'
|
|
|
|
$analyticsProvider.api.setCustomVariable = function (varIndex, varName, value, scope = 'page') {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('setCustomVariable', varIndex, varName, value, scope);
|
2021-08-10 22:45:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// scope: visit or page. Defaults to 'page'
|
|
|
|
$analyticsProvider.api.deleteCustomVariable = function (varIndex, scope = 'page') {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('deleteCustomVariable', varIndex, scope);
|
2021-08-10 22:45:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// trackSiteSearch(keyword, category, [searchCount])
|
|
|
|
$analyticsProvider.api.trackSiteSearch = function (keyword, category, searchCount) {
|
|
|
|
// keyword is required
|
|
|
|
if (keyword) {
|
|
|
|
const params = ['trackSiteSearch', keyword, category || false];
|
|
|
|
|
|
|
|
// searchCount is optional
|
|
|
|
if (angular.isDefined(searchCount)) {
|
|
|
|
params.push(searchCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
push(params);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// logs a conversion for goal 1. revenue is optional
|
|
|
|
// trackGoal(goalID, [revenue]);
|
|
|
|
$analyticsProvider.api.trackGoal = function (goalID, revenue) {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('trackGoal', goalID, revenue || 0);
|
2021-08-10 22:45:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// track outlink or download
|
|
|
|
// linkType is 'link' or 'download', 'link' by default
|
|
|
|
// trackLink(url, [linkType]);
|
|
|
|
$analyticsProvider.api.trackLink = function (url, linkType) {
|
|
|
|
const type = linkType || 'link';
|
2022-01-03 15:49:59 +00:00
|
|
|
push('trackLink', url, type);
|
2021-08-10 22:45:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Set default angulartics page and event tracking
|
|
|
|
|
|
|
|
$analyticsProvider.registerSetUsername(function (username) {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('setUserId', username);
|
2021-08-10 22:45:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// locationObj is the angular $location object
|
|
|
|
$analyticsProvider.registerPageTrack(function (path) {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('setDocumentTitle', $window.document.title);
|
|
|
|
push('setReferrerUrl', '');
|
|
|
|
push('setCustomUrl', basePath + path);
|
|
|
|
push('trackPageView');
|
2021-08-10 22:45:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name eventTrack
|
|
|
|
* Track a basic event in Piwik, or send an ecommerce event.
|
|
|
|
*
|
|
|
|
* @param {string} action A string corresponding to the type of event that needs to be tracked.
|
|
|
|
* @param {object} properties The properties that need to be logged with the event.
|
|
|
|
*/
|
2022-01-03 15:49:59 +00:00
|
|
|
$analyticsProvider.registerEventTrack(trackEvent);
|
2021-08-10 22:45:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name exceptionTrack
|
|
|
|
* Sugar on top of the eventTrack method for easily handling errors
|
|
|
|
*
|
|
|
|
* @param {object} error An Error object to track: error.toString() used for event 'action', error.stack used for event 'label'.
|
|
|
|
* @param {object} cause The cause of the error given from $exceptionHandler, not used.
|
|
|
|
*/
|
|
|
|
$analyticsProvider.registerExceptionTrack(function (error) {
|
2022-01-03 15:49:59 +00:00
|
|
|
push('trackEvent', 'Exceptions', error.toString(), error.stack, 0);
|
2021-08-10 22:45:53 +00:00
|
|
|
});
|
|
|
|
}
|