Skip to content

Commit

Permalink
[main] correct types define for stopTrackEvent and stopTrackPage for #…
Browse files Browse the repository at this point in the history
…2209 (#2270)

* change types

* Update README.md
  • Loading branch information
siyuniu-ms committed Feb 13, 2024
1 parent b5b9eea commit d4b3c27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions AISKU/src/AISku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export class AppInsightsSku implements IApplicationInsights {
* @param properties map[string, string] - additional data used to filter pages and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
*/
public stopTrackPage(name?: string, url?: string, customProperties?: { [key: string]: any; }, measurements?: { [key: string]: number; }) {
public stopTrackPage(name?: string, url?: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
}

Expand All @@ -665,7 +665,7 @@ export class AppInsightsSku implements IApplicationInsights {
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
*/
public stopTrackEvent(name: string, properties?: { [key: string]: string; }, measurements?: { [key: string]: number; }) {
public stopTrackEvent(name: string, properties?: { [key: string]: string }, measurements?: { [key: string]: number }) {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
}

Expand Down
21 changes: 8 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ appInsights.trackTrace({message: 'some trace'});
appInsights.trackMetric({name: 'some metric', average: 42});
appInsights.trackDependencyData({absoluteUrl: 'some url', responseCode: 200, method: 'GET', id: 'some id'});
appInsights.startTrackPage("pageName");
appInsights.stopTrackPage("pageName", null, {customProp1: "some value"});
appInsights.stopTrackPage("pageName", null, {customePropertiesName: "some value"}, {customerMeasurementsName: 144});
appInsights.startTrackEvent("event");
appInsights.stopTrackEvent("event", null, {customProp1: "some value"});
appInsights.stopTrackEvent("event", null, {customePropertiesName: "some value"}, {customerMeasurementsName: 150});
appInsights.flush();
```

Custom properties can be included in your telemetry through the `properties` named argument. This can be done with *any* of the Track APIs.
Custom properties can be included in your telemetry through the `properties` named argument. This can be done with *any* of the Track APIs except stopTrackPage and stopTrackEvent.

```js
appInsights.trackEvent({
Expand All @@ -234,16 +234,11 @@ appInsights.trackEvent({
});
```

```js
appInsights.startTrackEvent("event name");
appInsights.stopTrackEvent("event name", {
prop1: 3.14,
prop2: 'string',
prop3: {nested:"objects are okay too"}
}
)
```
If you wish to organize customer properties into separate sections based on properties and measurements for better visualization on the Azure Portal, consider using the following code:
When using stopTrackPage and stopTrackEvent, you can pass in data categorized by types:

Strings: These should be included under the properties field.
Numbers: Add these under the measurements field.
Remember, the order of the properties and measurements should not be altered. You can achieve this using the following code structure:

```js
appInsights.startTrackEvent("event name");
Expand Down
4 changes: 2 additions & 2 deletions shared/AppInsightsCommon/src/Interfaces/IAppInsights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface IAppInsights {
trackTrace(trace: ITraceTelemetry, customProperties?: {[key: string]: any}): void;
trackMetric(metric: IMetricTelemetry, customProperties?: {[key: string]: any}): void;
startTrackPage(name?: string): void;
stopTrackPage(name?: string, url?: string, customProperties?: Object): void;
stopTrackPage(name?: string, url?: string, properties?: {[key: string]: string}, measurements?: {[key: string]: number}): void;
startTrackEvent(name: string): void;
stopTrackEvent(name: string, properties?: Object, measurements?: Object): void;
stopTrackEvent(name: string, properties?: {[key: string]: string}, measurements?: {[key: string]: number}): void;
addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): void;
trackPageViewPerformance(pageViewPerformance: IPageViewPerformanceTelemetry, customProperties?: { [key: string]: any }): void;
}

0 comments on commit d4b3c27

Please sign in to comment.