├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTE.md ├── Gruntfile.js ├── LICENSE ├── README.md ├── bower.json ├── dist ├── angular-appinsights.js └── angular-appinsights.min.js ├── lib └── angular-appinsights.js ├── package.json └── sample ├── angular-appinsights.js ├── appInsights.js ├── index.html ├── main.js ├── page1.html ├── page2.html └── styles.css /.gitignore: -------------------------------------------------------------------------------- 1 | # https://git-scm.com/docs/gitignore 2 | # https://help.github.com/articles/ignoring-files 3 | # Example .gitignore files: https://github.com/github/gitignore 4 | 5 | node_modules -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## [Unreleased] 8 | ### Changed 9 | - Update CHANGELOG.md to conform to [Keep a Changelog](http://keepachangelog.com/) 10 | 11 | ## [0.0.4] - 2016-12-13 12 | ### Added 13 | - Add build using GruntJS - thanks @jt000 14 | - Add minification - thanks @jt000 15 | - Add stub for easy testing when window.appInsights is not available - thanks @jt000 16 | 17 | ### Changed 18 | - Allow access to full application insights object - thanks @jt000 19 | - Allow appId to be optionally set in AppInsights prescribed way (during script initialization). This also enables additional config options to be set w/o having to go through start() - thanks @jt000 20 | 21 | ## [0.0.3] - 2014-12-22 22 | ### Added 23 | - Add support for Application Insights on Azure 24 | 25 | ## [0.0.2] - 2014-07-12 26 | - Initial Release 27 | 28 | [Unreleased]: https://github.com/johnhidey/angular-appinsights/tree/HEAD 29 | [0.0.4]: https://github.com/johnhidey/angular-appinsights/tree/v0.0.4 30 | [0.0.3]: https://github.com/johnhidey/angular-appinsights/tree/v0.0.3 31 | [0.0.2]: https://github.com/johnhidey/angular-appinsights/tree/v0.0.2 32 | -------------------------------------------------------------------------------- /CONTRIBUTE.md: -------------------------------------------------------------------------------- 1 | # Contribution 2 | 3 | To make changes to `angular-appinsights.js` alter the file located in the `lib` folder and then build using the instructions below to populate the `dist` and `sample` files. 4 | 5 | ## Building 6 | 7 | If you already have NPM & Grunt-CLI installed, then jump to step 3. 8 | 9 | ### Step 1: Install NPM 10 | 11 | Install NPM by following [the instructions on NPM's site](https://docs.npmjs.com/getting-started/installing-node) 12 | 13 | ### Step 2: Install Grunt CLI 14 | 15 | Run `npm install -g grunt-cli` on the command line to install the Grunt Command Line Interface 16 | 17 | ### Step 3: Install packages 18 | 19 | In your `angular-appinsights` folder (you cloned this repository locally, right?) run: `npm install` 20 | 21 | ### Step 4: Build via Grunt 22 | 23 | In your `angular-appinsights` folder run: `grunt` -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /*global module:false*/ 2 | module.exports = function (grunt) { 3 | 4 | // Project configuration. 5 | grunt.initConfig({ 6 | // Metadata. 7 | pkg: grunt.file.readJSON('package.json'), 8 | banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + 9 | '<%= grunt.template.today("yyyy-mm-dd") %>\n' + 10 | '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' + 11 | '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' + 12 | ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', 13 | // Task configuration. 14 | concat: { 15 | options: { 16 | banner: '<%= banner %>', 17 | stripBanners: true 18 | }, 19 | dist: { 20 | src: ['lib/<%= pkg.name %>.js'], 21 | dest: 'dist/<%= pkg.name %>.js' 22 | } 23 | }, 24 | uglify: { 25 | options: { 26 | banner: '<%= banner %>' 27 | }, 28 | dist: { 29 | src: '<%= concat.dist.dest %>', 30 | dest: 'dist/<%= pkg.name %>.min.js' 31 | } 32 | }, 33 | jshint: { 34 | options: { 35 | curly: true, 36 | eqeqeq: true, 37 | immed: true, 38 | latedef: 'nofunc', 39 | newcap: true, 40 | noarg: true, 41 | sub: true, 42 | undef: true, 43 | unused: true, 44 | boss: true, 45 | eqnull: true, 46 | globals: { 47 | window: true, 48 | console: true 49 | } 50 | }, 51 | gruntfile: { 52 | src: ['Gruntfile.js', 'lib/**/*.js'] 53 | } 54 | }, 55 | copy: { 56 | to_sample: { 57 | src: '<%= concat.dist.dest %>', 58 | dest: 'sample/<%= pkg.name %>.js' 59 | } 60 | }, 61 | watch: { 62 | gruntfile: { 63 | files: '<%= jshint.gruntfile.src %>', 64 | tasks: ['jshint:gruntfile'] 65 | } 66 | } 67 | }); 68 | 69 | // These plugins provide necessary tasks. 70 | grunt.loadNpmTasks('grunt-contrib-concat'); 71 | grunt.loadNpmTasks('grunt-contrib-uglify'); 72 | grunt.loadNpmTasks('grunt-contrib-jshint'); 73 | grunt.loadNpmTasks('grunt-contrib-watch'); 74 | grunt.loadNpmTasks('grunt-contrib-copy'); 75 | 76 | // Default task. 77 | grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'copy:to_sample']); 78 | 79 | }; 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 John Hidey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Stories in Ready](https://badge.waffle.io/johnhidey/angular-appinsights.png?label=ready&title=Ready)](https://waffle.io/johnhidey/angular-appinsights) 2 | [![Stories in Progress](https://badge.waffle.io/johnhidey/angular-appinsights.png?label=in%20progress&title=In%20Progress)](https://waffle.io/johnhidey/angular-appinsights) 3 | [![Known Vulnerabilities](https://snyk.io/test/npm/angular-appinsights/badge.svg)](https://snyk.io/test/npm/angular-appinsights) 4 | 5 | Angular-AppInsights 6 | =================== 7 | 8 | Angular-AppInsights is an angular module for using Microsoft's Application Insights within a SPA (Single Page Application). 9 | 10 | ## Usage 11 | Get your regular Microsoft's Application Insights 12 | ```HTML 13 | 20 | 30 | ``` 31 | 32 | You tag should look like this when modified: 33 | ```HTML 34 | 41 | 47 | ``` 48 | 49 | **Note**: You can apply other settings here for application insights if you choose. See the Microsoft documentation for [IConfig](https://github.com/Microsoft/ApplicationInsights-JS/blob/master/API-reference.md#config) for possible parameters. 50 | 51 | Include the following script tag 52 | 53 | ```HTML 54 | 55 | ``` 56 | 57 | on your SPA shell page (perferrably at the bottom of the ``). Now all we need to do is initialize the `angular-appinsights ` 58 | module and we're done. The best place to initialize `angular-appinsights` is in your application bootstrap. Below is sample of 59 | what this might look like. Make sure to take note that the application now has a dependency on `angular-appinsights`. 60 | 61 | ```JavaScript 62 | angular.module('insightsApp', ['ngRoute', 'angular-appinsights']) 63 | .config(['$routeProvider', 'insightsProvider', function ($routeProvider, insightsProvider) { 64 | 65 | $routeProvider 66 | .when('/', { 67 | templateUrl: "page1.html", 68 | controller: 'page1Controller' 69 | }) 70 | .when('/page2', { 71 | templateUrl: "page2.html" 72 | }); 73 | 74 | // Add application insights id here 75 | insightsProvider.start('Application Insights Application Id'); 76 | }]) 77 | ``` 78 | 79 | You angular application will now log all page views defined by subscribing to the event `locationChangeSuccess` within angular. 80 | You're up and logging page views now. 81 | 82 | To log custom events you just need to have a dependency on `insights` and Angular's DI will deliver you the object. From there it is 83 | pretty simple. You will call `insights.logEvent()` passing your event data. For a complete definition of the method please refer to 84 | Microsoft's document on [logEvent](http://msdn.microsoft.com/en-us/library/dn614099.aspx). You can also log page views by calling 85 | `insights.logPageView()`. For a complete definition of the method please refer to Microsoft's document on 86 | [logPageView](http://msdn.microsoft.com/en-us/library/dn614096.aspx). Below is a sample where the `page1Controller` is logging it's activation. 87 | 88 | ```JavaScript 89 | angular.module('insightsApp', ['ngRoute', 'angular-appinsights']) 90 | .config(['$routeProvider', 'insightsProvider', function ($routeProvider, insightsProvider) { 91 | 92 | $routeProvider 93 | .when('/', { 94 | templateUrl: "page1.html", 95 | controller: 'page1Controller' 96 | }) 97 | .when('/page2', { 98 | templateUrl: "page2.html" 99 | }); 100 | 101 | // Add application insights id here 102 | insightsProvider.start('Application Insights Application Id'); 103 | 104 | }]) 105 | .controller('page1Controller', ['$scope', 'insights', function($scope, insights) { 106 | 107 | insights.logEvent('Page 1 Controller Activated'); 108 | 109 | }]); 110 | ``` 111 | 112 | ## API 113 | 114 | ### start(appId, appName) 115 | 116 | Initializes the Application Insights object with default settings using the provided `appId` and optional `appName`. 117 | 118 | * `appId` (string) - The key of your Application Insights resource in Azure. 119 | * `appName` (string) - *Optional.* Text that is prepended to the path information when the angular page is changed. **Default:** `(Application Root)` 120 | 121 | #### Example 122 | 123 | ```JavaScript 124 | insightsProvider.start('00000000-0000-0000-0000-000000000000', 'MyApp'); 125 | ``` 126 | 127 | ### start(options) 128 | 129 | Initializes the Application Insights object with settings applied from an options object. 130 | 131 | #### Example 132 | 133 | ```JavaScript 134 | var options = { 135 | appId: '00000000-0000-0000-0000-000000000000', 136 | appName: 'MyApp' 137 | }; 138 | insightsProvider.start(options); 139 | ``` 140 | 141 | ##Change Log 142 | Please see [`CHANGELOG.md`](CHANGELOG.md) 143 | 144 | ##License 145 | MIT. Please see [`LICENSE`](LICENSE) 146 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-appinsights", 3 | "main": "dist/angular-appinsights.js", 4 | "version": "0.0.4", 5 | "homepage": "https://github.com/johnhidey/angular-appinsights", 6 | "authors": [ 7 | "johnhidey " 8 | ], 9 | "description": "A angular module for using Microsoft's Application Insights within a SPA", 10 | "keywords": [ 11 | "appinsights", 12 | "metrics", 13 | "spa", 14 | "applicationinsights" 15 | ], 16 | "license": "MIT", 17 | "ignore": [ 18 | "**/.*", 19 | "node_modules", 20 | "bower_components" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /dist/angular-appinsights.js: -------------------------------------------------------------------------------- 1 | /*! angular-appinsights - v0.0.4 - 2016-12-13 2 | * https://github.com/johnhidey/angular-appinsights#readme 3 | * Copyright (c) 2016 ; Licensed */ 4 | (function () { 5 | "use strict"; 6 | 7 | angular.module('angular-appinsights', []) 8 | .provider('insights', InsightsProvider) 9 | .run(['$rootScope', '$location', 'insights', onAppRun]); 10 | 11 | var _appName = ''; 12 | var _stub = { 13 | startTrackPage: angular.noop, 14 | stopTrackPage: angular.noop, 15 | trackPageView: angular.noop, 16 | startTrackEvent: angular.noop, 17 | stopTrackEvent: angular.noop, 18 | trackEvent: angular.noop, 19 | trackDependency: angular.noop, 20 | trackException: angular.noop, 21 | trackMetric: angular.noop, 22 | trackTrace: angular.noop, 23 | flush: angular.noop, 24 | setAuthenticatedUserContext: angular.noop, 25 | clearAuthenticatedUserContext: angular.noop, 26 | }; 27 | 28 | function InsightsProvider() { 29 | 30 | this.start = function (appId, appName) { 31 | 32 | var options; 33 | if (angular.isObject(appId)) { 34 | options = appId; 35 | } else if (angular.isString(appId)) { 36 | options = { 37 | appId: appId, 38 | appName: appName 39 | }; 40 | } 41 | 42 | initialize(options); 43 | }; 44 | 45 | this.$get = function () { 46 | return window.appInsights || _stub; 47 | }; 48 | 49 | function initialize(options) { 50 | 51 | _appName = options.appName || '(Application Root)'; 52 | 53 | if (options.appId) { 54 | if (window.appInsights.start) { 55 | window.appInsights.start(options.appId); 56 | } else if (angular.isFunction(window.appInsights)) { 57 | window.appInsights = window.appInsights({ instrumentationKey: options.appId }); 58 | } else if (window.appInsights.config) { 59 | window.appInsights.config.instrumentationKey = options.appId; 60 | } 61 | } 62 | 63 | if (!window.appInsights.config.instrumentationKey) { 64 | console.warn('Application Insights not initialized'); 65 | } 66 | } 67 | } 68 | 69 | function onAppRun($rootScope, $location, insights) { 70 | 71 | $rootScope.$on('$locationChangeStart', function () { 72 | var pagePath; 73 | try { 74 | pagePath = _appName + '/' + $location.path().substr(1); 75 | } 76 | finally { 77 | insights.startTrackPage(pagePath); 78 | } 79 | }); 80 | 81 | $rootScope.$on('$locationChangeSuccess', function (e, newUrl) { 82 | var pagePath; 83 | try { 84 | pagePath = _appName + '/' + $location.path().substr(1); 85 | } 86 | finally { 87 | insights.stopTrackPage(pagePath, newUrl); 88 | } 89 | }); 90 | } 91 | 92 | } ()); 93 | -------------------------------------------------------------------------------- /dist/angular-appinsights.min.js: -------------------------------------------------------------------------------- 1 | /*! angular-appinsights - v0.0.4 - 2016-12-13 2 | * https://github.com/johnhidey/angular-appinsights#readme 3 | * Copyright (c) 2016 ; Licensed */ 4 | !function(){"use strict";function a(){function a(a){c=a.appName||"(Application Root)",a.appId&&(window.appInsights.start?window.appInsights.start(a.appId):angular.isFunction(window.appInsights)?window.appInsights=window.appInsights({instrumentationKey:a.appId}):window.appInsights.config&&(window.appInsights.config.instrumentationKey=a.appId)),window.appInsights.config.instrumentationKey||console.warn("Application Insights not initialized")}this.start=function(b,c){var d;angular.isObject(b)?d=b:angular.isString(b)&&(d={appId:b,appName:c}),a(d)},this.$get=function(){return window.appInsights||d}}function b(a,b,d){a.$on("$locationChangeStart",function(){var a;try{a=c+"/"+b.path().substr(1)}finally{d.startTrackPage(a)}}),a.$on("$locationChangeSuccess",function(a,e){var f;try{f=c+"/"+b.path().substr(1)}finally{d.stopTrackPage(f,e)}})}angular.module("angular-appinsights",[]).provider("insights",a).run(["$rootScope","$location","insights",b]);var c="",d={startTrackPage:angular.noop,stopTrackPage:angular.noop,trackPageView:angular.noop,startTrackEvent:angular.noop,stopTrackEvent:angular.noop,trackEvent:angular.noop,trackDependency:angular.noop,trackException:angular.noop,trackMetric:angular.noop,trackTrace:angular.noop,flush:angular.noop,setAuthenticatedUserContext:angular.noop,clearAuthenticatedUserContext:angular.noop}}(); -------------------------------------------------------------------------------- /lib/angular-appinsights.js: -------------------------------------------------------------------------------- 1 | 2 | /*global angular: true */ 3 | (function () { 4 | "use strict"; 5 | 6 | angular.module('angular-appinsights', []) 7 | .provider('insights', InsightsProvider) 8 | .run(['$rootScope', '$location', 'insights', onAppRun]); 9 | 10 | var _appName = ''; 11 | var _stub = { 12 | startTrackPage: angular.noop, 13 | stopTrackPage: angular.noop, 14 | trackPageView: angular.noop, 15 | startTrackEvent: angular.noop, 16 | stopTrackEvent: angular.noop, 17 | trackEvent: angular.noop, 18 | trackDependency: angular.noop, 19 | trackException: angular.noop, 20 | trackMetric: angular.noop, 21 | trackTrace: angular.noop, 22 | flush: angular.noop, 23 | setAuthenticatedUserContext: angular.noop, 24 | clearAuthenticatedUserContext: angular.noop, 25 | }; 26 | 27 | function InsightsProvider() { 28 | 29 | this.start = function (appId, appName) { 30 | 31 | var options; 32 | if (angular.isObject(appId)) { 33 | options = appId; 34 | } else if (angular.isString(appId)) { 35 | options = { 36 | appId: appId, 37 | appName: appName 38 | }; 39 | } 40 | 41 | initialize(options); 42 | }; 43 | 44 | this.$get = function () { 45 | return window.appInsights || _stub; 46 | }; 47 | 48 | function initialize(options) { 49 | 50 | _appName = options.appName || '(Application Root)'; 51 | 52 | if (options.appId) { 53 | if (window.appInsights.start) { 54 | window.appInsights.start(options.appId); 55 | } else if (angular.isFunction(window.appInsights)) { 56 | window.appInsights = window.appInsights({ instrumentationKey: options.appId }); 57 | } else if (window.appInsights.config) { 58 | window.appInsights.config.instrumentationKey = options.appId; 59 | } 60 | } 61 | 62 | if (!window.appInsights.config.instrumentationKey) { 63 | console.warn('Application Insights not initialized'); 64 | } 65 | } 66 | } 67 | 68 | function onAppRun($rootScope, $location, insights) { 69 | 70 | $rootScope.$on('$locationChangeStart', function () { 71 | var pagePath; 72 | try { 73 | pagePath = _appName + '/' + $location.path().substr(1); 74 | } 75 | finally { 76 | if(insights.startTrackPage) 77 | insights.startTrackPage(pagePath); 78 | } 79 | }); 80 | 81 | $rootScope.$on('$locationChangeSuccess', function (e, newUrl) { 82 | var pagePath; 83 | try { 84 | pagePath = _appName + '/' + $location.path().substr(1); 85 | } 86 | finally { 87 | if(insights.stopTrackPage) 88 | insights.stopTrackPage(pagePath, newUrl); 89 | } 90 | }); 91 | } 92 | 93 | } ()); 94 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-appinsights", 3 | "version": "0.0.4", 4 | "description": "A angular module for using Microsoft's Application Insights within a SPA", 5 | "engines": { 6 | "node": ">= 0.10.0" 7 | }, 8 | "dependencies": {}, 9 | "devDependencies": { 10 | "grunt": "~0.4.5", 11 | "grunt-contrib-concat": "~0.4.0", 12 | "grunt-contrib-copy": "^1.0.0", 13 | "grunt-contrib-jshint": "~0.10.0", 14 | "grunt-contrib-uglify": "~0.5.0", 15 | "grunt-contrib-watch": "~0.6.1" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/johnhidey/angular-appinsights.git" 20 | }, 21 | "author": "johnhidey", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/johnhidey/angular-appinsights/issues" 25 | }, 26 | "homepage": "https://github.com/johnhidey/angular-appinsights#readme" 27 | } 28 | -------------------------------------------------------------------------------- /sample/angular-appinsights.js: -------------------------------------------------------------------------------- 1 | /*! angular-appinsights - v0.0.4 - 2016-12-13 2 | * https://github.com/johnhidey/angular-appinsights#readme 3 | * Copyright (c) 2016 ; Licensed */ 4 | (function () { 5 | "use strict"; 6 | 7 | angular.module('angular-appinsights', []) 8 | .provider('insights', InsightsProvider) 9 | .run(['$rootScope', '$location', 'insights', onAppRun]); 10 | 11 | var _appName = ''; 12 | var _stub = { 13 | startTrackPage: angular.noop, 14 | stopTrackPage: angular.noop, 15 | trackPageView: angular.noop, 16 | startTrackEvent: angular.noop, 17 | stopTrackEvent: angular.noop, 18 | trackEvent: angular.noop, 19 | trackDependency: angular.noop, 20 | trackException: angular.noop, 21 | trackMetric: angular.noop, 22 | trackTrace: angular.noop, 23 | flush: angular.noop, 24 | setAuthenticatedUserContext: angular.noop, 25 | clearAuthenticatedUserContext: angular.noop, 26 | }; 27 | 28 | function InsightsProvider() { 29 | 30 | this.start = function (appId, appName) { 31 | 32 | var options; 33 | if (angular.isObject(appId)) { 34 | options = appId; 35 | } else if (angular.isString(appId)) { 36 | options = { 37 | appId: appId, 38 | appName: appName 39 | }; 40 | } 41 | 42 | initialize(options); 43 | }; 44 | 45 | this.$get = function () { 46 | return window.appInsights || _stub; 47 | }; 48 | 49 | function initialize(options) { 50 | 51 | _appName = options.appName || '(Application Root)'; 52 | 53 | if (options.appId) { 54 | if (window.appInsights.start) { 55 | window.appInsights.start(options.appId); 56 | } else if (angular.isFunction(window.appInsights)) { 57 | window.appInsights = window.appInsights({ instrumentationKey: options.appId }); 58 | } else if (window.appInsights.config) { 59 | window.appInsights.config.instrumentationKey = options.appId; 60 | } 61 | } 62 | 63 | if (!window.appInsights.config.instrumentationKey) { 64 | console.warn('Application Insights not initialized'); 65 | } 66 | } 67 | } 68 | 69 | function onAppRun($rootScope, $location, insights) { 70 | 71 | $rootScope.$on('$locationChangeStart', function () { 72 | var pagePath; 73 | try { 74 | pagePath = _appName + '/' + $location.path().substr(1); 75 | } 76 | finally { 77 | insights.startTrackPage(pagePath); 78 | } 79 | }); 80 | 81 | $rootScope.$on('$locationChangeSuccess', function (e, newUrl) { 82 | var pagePath; 83 | try { 84 | pagePath = _appName + '/' + $location.path().substr(1); 85 | } 86 | finally { 87 | insights.stopTrackPage(pagePath, newUrl); 88 | } 89 | }); 90 | } 91 | 92 | } ()); 93 | -------------------------------------------------------------------------------- /sample/appInsights.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | var appInsights=window.appInsights||function(config){ 3 | function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o='script',s='AuthenticatedUserContext',h='start',c='stop',l='Track',a=l+'Event',v=l+'Page',y=u.createElement(o),r,f;y.src=config.url||'https://az416426.vo.msecnd.net/scripts/a/ai.0.js';u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version='1.0',r=['Event','Exception','Metric','PageView','Trace','Dependency'];r.length;)i('track'+r.pop());return i('set'+s),i('clear'+s),i(h+a),i(c+a),i(h+v),i(c+v),i('flush'),config.disableExceptionTracking||(r='onerror',i('_'+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t['_'+r](config,i,u,e,o),s}),t 4 | }({ 5 | disableTelemetry: true // Note: Remove this to start tracking usage in production 6 | }); 7 | 8 | window.appInsights=appInsights; 9 | }()); 10 | 11 | -------------------------------------------------------------------------------- /sample/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insights Demo 6 | 7 | 8 | 9 | 10 | Page 1 11 | Page 2 12 | 13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /sample/main.js: -------------------------------------------------------------------------------- 1 | // fe43bead-b7b1-4e6c-b273-5a101ba16b9c 2 | /*global angular: true */ 3 | 4 | (function () { 5 | "use strict"; 6 | 7 | angular.module('insightsApp', ['ngRoute', 'angular-appinsights']) 8 | .config(['$routeProvider', 'insightsProvider', function ($routeProvider, insightsProvider) { 9 | 10 | $routeProvider 11 | .when('/', { 12 | templateUrl: "page1.html", 13 | controller: 'page1Controller' 14 | }) 15 | .when('/page2', { 16 | templateUrl: "page2.html" 17 | }); 18 | 19 | // Add application insights id here 20 | insightsProvider.start('Application Insights App Id Goes Here'); 21 | 22 | }]) 23 | .controller('page1Controller', ['$scope', 'insights', function($scope, insights) { 24 | 25 | insights.logEvent('Page 1 Controller Activated'); 26 | 27 | $scope.exit = function () { 28 | insights.logEvent('User clicked the exit button'); 29 | }; 30 | }]); 31 | 32 | }()); 33 | -------------------------------------------------------------------------------- /sample/page1.html: -------------------------------------------------------------------------------- 1 |

Page 1

2 | 3 | -------------------------------------------------------------------------------- /sample/page2.html: -------------------------------------------------------------------------------- 1 |

Page 2

2 | -------------------------------------------------------------------------------- /sample/styles.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: red; 3 | } 4 | 5 | body { 6 | background-color: #ffffff; 7 | } 8 | 9 | a, a:link, a:hover, a:visited, a:active { 10 | color: blue; 11 | } 12 | --------------------------------------------------------------------------------