Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
EVG-20863: Add userId as custom attribute in New Relic (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
minnakt authored Sep 12, 2023
1 parent 9608c99 commit e46a533
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/analytics/useAnalyticAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ import { useEffect } from "react";
import { useLogContext } from "context/LogContext";

export const useAnalyticAttributes = () => {
const { logMetadata } = useLogContext();
const { newrelic } = window;

const { logMetadata } = useLogContext();
const { logType } = logMetadata || {};

const userId = localStorage.getItem("userId");

useEffect(() => {
if (typeof newrelic !== "object") {
console.debug("Setting logType: ", logType);
console.debug("Setting userId: ", userId);
return;
}
if (logType !== undefined) {
newrelic.setCustomAttribute("logType", logType);
}
}, [logType, newrelic]);
if (userId !== null) {
newrelic.setCustomAttribute("userId", userId);
}
}, [userId, logType, newrelic]);
};

0 comments on commit e46a533

Please sign in to comment.