@@ -2,12 +2,13 @@ import {Injectable} from '@angular/core';
2
2
import { IAppInsights , IConfig , SeverityLevel } from '../models/app-insights' ;
3
3
4
4
declare var appInsights : IAppInsights ;
5
+ declare var mixpanel : any ;
5
6
6
7
function AiDefined ( ) {
7
8
return ( target : Object , functionName : string , descriptor : TypedPropertyDescriptor < any > ) => {
8
9
let originalMethod = descriptor . value ;
9
10
descriptor . value = function ( ...args : any [ ] ) {
10
- if ( typeof ( appInsights ) !== 'undefined' &&
11
+ if ( typeof ( appInsights ) !== 'undefined' && typeof ( mixpanel ) !== 'undefined' &&
11
12
typeof ( appInsights [ functionName ] ) !== 'undefined' ) {
12
13
return originalMethod . apply ( this , args ) ;
13
14
} else {
@@ -61,9 +62,16 @@ export class AiService implements IAppInsights {
61
62
*/
62
63
@AiDefined ( )
63
64
startTrackPage ( name ?: string ) {
65
+ mixpanel . track ( 'Functions Start Page View' , { page : name , properties : this . addMixPanelProperties ( null ) } ) ;
64
66
return appInsights . startTrackPage ( name ) ;
65
67
}
66
68
69
+ addMixPanelProperties ( properties ?) {
70
+ properties = properties || { } ;
71
+ properties [ 'sitename' ] = 'functions' ;
72
+ properties [ "correlationId" ] = mixpanel . get_distinct_id ( ) ;
73
+ }
74
+
67
75
/**
68
76
* Logs how long a page or other item was visible, after {@link startTrackPage}. Call this when the page closes.
69
77
* @param name The string you used as the name in startTrackPage. Defaults to the document title.
@@ -73,6 +81,7 @@ export class AiService implements IAppInsights {
73
81
*/
74
82
@AiDefined ( )
75
83
stopTrackPage ( name ?: string , url ?: string , properties ?: { [ name : string ] : string ; } , measurements ?: { [ name : string ] : number ; } ) {
84
+ mixpanel . track ( 'Functions Stop Page View' , { page : name , url : url , properties : this . addMixPanelProperties ( properties ) , measurements : measurements } ) ;
76
85
return appInsights . stopTrackPage ( name , url , properties , measurements ) ;
77
86
}
78
87
@@ -86,6 +95,7 @@ export class AiService implements IAppInsights {
86
95
*/
87
96
@AiDefined ( )
88
97
trackPageView ( name ?: string , url ?: string , properties ?: { [ name : string ] : string ; } , measurements ?: { [ name : string ] : number ; } , duration ?: number ) {
98
+ mixpanel . track ( 'Functions Page Viewed' , { page : name , url : url , properties : this . addMixPanelProperties ( properties ) , measurements : measurements } ) ;
89
99
return appInsights . trackPageView ( name , url , properties , measurements ) ;
90
100
}
91
101
@@ -95,6 +105,7 @@ export class AiService implements IAppInsights {
95
105
*/
96
106
@AiDefined ( )
97
107
startTrackEvent ( name : string ) {
108
+ mixpanel . track ( name ) ;
98
109
return appInsights . startTrackEvent ( name ) ;
99
110
}
100
111
@@ -106,7 +117,8 @@ export class AiService implements IAppInsights {
106
117
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
107
118
*/
108
119
@AiDefined ( )
109
- stopTrackEvent ( name : string , properties ?: { [ name : string ] : string ; } , measurements ?: { [ name : string ] : number ; } ) {
120
+ stopTrackEvent ( name : string , properties ?: { [ name : string ] : string ; } , measurements ?: { [ name : string ] : number ; } ) {
121
+ mixpanel . track ( name , { properties : this . addMixPanelProperties ( properties ) , measurements : measurements } ) ;
110
122
return appInsights . stopTrackEvent ( name , properties , measurements ) ;
111
123
}
112
124
@@ -118,6 +130,7 @@ export class AiService implements IAppInsights {
118
130
*/
119
131
@AiDefined ( )
120
132
trackEvent ( name : string , properties ?: { [ name : string ] : string ; } , measurements ?: { [ name : string ] : number ; } ) {
133
+ mixpanel . track ( name , { properties : this . addMixPanelProperties ( properties ) , measurements : measurements } ) ;
121
134
return appInsights . trackEvent ( name , properties , measurements ) ;
122
135
}
123
136
@@ -159,7 +172,8 @@ export class AiService implements IAppInsights {
159
172
* @param max The largest measurement in the sample. Defaults to the average.
160
173
*/
161
174
@AiDefined ( )
162
- trackMetric ( name : string , average : number , sampleCount ?: number , min ?: number , max ?: number , properties ?: { [ name : string ] : string ; } ) {
175
+ trackMetric ( name : string , average : number , sampleCount ?: number , min ?: number , max ?: number , properties ?: { [ name : string ] : string ; } ) {
176
+ mixpanel . track ( name , { average : average , sampleCount : sampleCount , min : min , max : max , properties : this . addMixPanelProperties ( properties ) } ) ;
163
177
return appInsights . trackMetric ( name , average , sampleCount , min , max , properties ) ;
164
178
}
165
179
@@ -192,6 +206,12 @@ export class AiService implements IAppInsights {
192
206
*/
193
207
@AiDefined ( )
194
208
setAuthenticatedUserContext ( authenticatedUserId : string , accountId ?: string ) {
209
+ var userDetails = authenticatedUserId . split ( "#" ) ;
210
+ if ( userDetails . length === 2 ) {
211
+ mixpanel . alias ( userDetails [ 1 ] ) ;
212
+ } else {
213
+ mixpanel . alias ( authenticatedUserId ) ;
214
+ }
195
215
return appInsights . setAuthenticatedUserContext ( authenticatedUserId , accountId ) ;
196
216
}
197
217
0 commit comments