Skip to content

Instantly share code, notes, and snippets.

@andrewconnell
Last active September 9, 2015 10:51
Show Gist options
  • Select an option

  • Save andrewconnell/9bbcc996fdde0d06ff5b to your computer and use it in GitHub Desktop.

Select an option

Save andrewconnell/9bbcc996fdde0d06ff5b to your computer and use it in GitHub Desktop.
azure.appInsights.service.js
(function () {
'use strict';
angular.module('appng-ffldraft-xlsaddin')
.service('azAppInsightService', [azAppInsightService]);
/**
* Custom Angular service.
*
*/
function azAppInsightService() {
return {
trackPageView: trackPageView,
trackEvent: trackEvent
}
init();
/** *********************************************************** */
function init() {
var config = appInsights.config;
config.enableDebug = true;
config.verboseLogging = true;
appInsights.config = config;
}
/**
* Track a page view.
*/
function trackPageView(pageName, url, leagueId, teamId) {
var configData = {
App: 'ExcelDraftAddin'
}
if (leagueId !== null && leagueId !== undefined) {
configData.LeagueId = leagueId;
}
if (teamId !== null && teamId !== undefined) {
configData.TeamId = teamId;
}
appInsights.trackPageView(pageName, url, configData);
}
/**
* Track custom event.
*/
function trackEvent(event, leagueId, teamId, data) {
var configData = {}
if (data !== null && data !== undefined) {
configData = data;
}
configData.App = 'ExcelDraftAddin';
if (leagueId !== null && leagueId !== undefined) {
configData.LeagueId = leagueId;
}
if (teamId !== null && teamId !== undefined) {
configData.TeamId = teamId;
}
appInsights.trackEvent(event, configData);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment