Skip to content

Commit 2c3b459

Browse files
update
2 parents f6a2e45 + f6d60c1 commit 2c3b459

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,5 @@ examples/**/**/package-lock.json
413413

414414
# playwright test result
415415
test-results
416+
417+
**/public

examples/express-app/server.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const exampleTargetingContextAccessor = {
1616
getTargetingContext: () => {
1717
const req = requestAccessor.getStore();
1818
if (req === undefined) {
19-
return { userId: undefined, groups: [] };
19+
return undefined;
2020
}
2121
// read user and groups from request query data
2222
const { userId, groups } = req.query;

examples/quote-of-the-day/client/src/pages/Home.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function Home() {
3939
headers: {
4040
"Content-Type": "application/json",
4141
},
42-
body: JSON.stringify({ UserId: currentUser ?? "" }),
42+
body: JSON.stringify({ userId: currentUser ?? "" }),
4343
});
4444

4545
if (response.ok) {

examples/quote-of-the-day/server.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ const exampleTargetingContextAccessor = {
1919
getTargetingContext: () => {
2020
const req = requestAccessor.getStore();
2121
if (req === undefined) {
22-
return { userId: undefined, groups: [] };
22+
return undefined;
2323
}
24-
// read user and groups from request query data
25-
const { userId, groups } = req.query;
24+
// read user and groups from request
25+
const userId = req.query.userId ?? req.body.userId;
26+
const groups = req.query.groups ?? req.body.groups;
2627
// return an ITargetingContext with the appropriate user info
2728
return { userId: userId, groups: groups ? groups.split(",") : [] };
2829
}
@@ -43,7 +44,7 @@ applicationInsights.defaultClient.addTelemetryProcessor(createTargetingTelemetry
4344

4445
const { load } = require("@azure/app-configuration-provider");
4546
const { FeatureManager, ConfigurationMapFeatureFlagProvider } = require("@microsoft/feature-management");
46-
const { createTelemetryPublisher, trackEvent } = require("@microsoft/feature-management-applicationinsights-node");
47+
const { createTelemetryPublisher } = require("@microsoft/feature-management-applicationinsights-node");
4748
let appConfig;
4849
let featureManager;
4950
async function initializeConfig() {
@@ -103,11 +104,11 @@ function startServer() {
103104
});
104105

105106
server.post("/api/like", (req, res) => {
106-
const { UserId } = req.body;
107-
if (UserId === undefined) {
107+
const { userId } = req.body;
108+
if (userId === undefined) {
108109
return res.status(400).send({ error: "UserId is required" });
109110
}
110-
trackEvent(applicationInsights.defaultClient, UserId, { name: "Like" });
111+
applicationInsights.defaultClient.trackEvent({ name: "Like" });
111112
res.status(200).send({ message: "Like event logged successfully" });
112113
});
113114

src/feature-management-applicationinsights-browser/src/telemetry.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ export function trackEvent(client: ApplicationInsights, targetingId: string, eve
4848
export function createTargetingTelemetryInitializer(targetingContextAccessor: ITargetingContextAccessor): (item: ITelemetryItem) => void {
4949
return (item: ITelemetryItem) => {
5050
const targetingContext = targetingContextAccessor.getTargetingContext();
51-
if (targetingContext?.userId === undefined) {
52-
console.warn("Targeting id is undefined.");
51+
if (targetingContext !== undefined) {
52+
if (targetingContext?.userId === undefined) {
53+
console.warn("Targeting id is undefined.");
54+
}
55+
item.data = {...item.data, [TARGETING_ID]: targetingContext?.userId || ""};
5356
}
54-
item.data = {...item.data, [TARGETING_ID]: targetingContext?.userId || ""};
5557
};
5658
}

src/feature-management-applicationinsights-node/src/telemetry.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ export function trackEvent(client: TelemetryClient, targetingId: string, event:
4848
export function createTargetingTelemetryProcessor(targetingContextAccessor: ITargetingContextAccessor): (envelope: Contracts.EnvelopeTelemetry) => boolean {
4949
return (envelope: Contracts.EnvelopeTelemetry) => {
5050
const targetingContext = targetingContextAccessor.getTargetingContext();
51-
if (targetingContext?.userId === undefined) {
52-
console.warn("Targeting id is undefined.");
51+
if (targetingContext !== undefined) {
52+
if (targetingContext?.userId === undefined) {
53+
console.warn("Targeting id is undefined.");
54+
}
55+
envelope.data.baseData = envelope.data.baseData || {};
56+
envelope.data.baseData.properties = {...envelope.data.baseData.properties, [TARGETING_ID]: targetingContext?.userId || ""};
5357
}
54-
envelope.data.baseData = envelope.data.baseData || {};
55-
envelope.data.baseData.properties = {...envelope.data.baseData.properties, [TARGETING_ID]: targetingContext?.userId || ""};
56-
return true; // If a telemetry processor returns false, that telemetry item isn't sent.
58+
return true;
5759
};
5860
}

0 commit comments

Comments
 (0)