Skip to content

Commit

Permalink
refactor: TAR-110 move initDatadog to main.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Chattox committed Apr 25, 2024
1 parent 9641889 commit d4a14ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import { datadogRum } from "@datadog/browser-rum";
import { SeoMetaTags } from "./components/SeoMetaTags/SeoMetaTags";
import Theme from "./components/Theme";
import { WithExtensionContext } from "./hooks/withExtensionContext";
import { useEffect } from "react";

function App() {
useEffect(() => {
const ddToken = import.meta.env.PUBLIC_DATADOG_TOKEN;
const ddId = import.meta.env.PUBLIC_DATADOG_ID;
const ddEnv = import.meta.env.PUBLIC_DATADOG_ENV;

if (ddToken && ddId && ddEnv) {
datadogRum.init({
applicationId: ddId,
clientToken: ddToken,
env: ddEnv,
site: "datadoghq.com",
service: "dc-extension-seo-meta-tags",
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
defaultPrivacyLevel: "allow",
sessionSampleRate: 100,
sessionReplaySampleRate: 100,
usePartitionedCrossSiteSessionCookie: true,
proxy: "https://dd-proxy.amplience.net",
});

datadogRum.startSessionReplayRecording();
}
}, []);

return (
<WithExtensionContext>
<Theme>
Expand Down
1 change: 1 addition & 0 deletions src/lib/datadog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { initDatadog } from "./initDatadog";
27 changes: 27 additions & 0 deletions src/lib/datadog/initDatadog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { datadogRum } from "@datadog/browser-rum";

export const initDatadog = () => {
const ddToken = import.meta.env.PUBLIC_DATADOG_TOKEN;
const ddId = import.meta.env.PUBLIC_DATADOG_ID;
const ddEnv = import.meta.env.PUBLIC_DATADOG_ENV;

if (ddToken && ddId && ddEnv) {
datadogRum.init({
applicationId: ddId,
clientToken: ddToken,
env: ddEnv,
site: "datadoghq.com",
service: "dc-extension-seo-meta-tags",
trackResources: true,
trackLongTasks: true,
trackUserInteractions: true,
defaultPrivacyLevel: "allow",
sessionSampleRate: 100,
sessionReplaySampleRate: 100,
usePartitionedCrossSiteSessionCookie: true,
proxy: "https://dd-proxy.amplience.net",
});

datadogRum.startSessionReplayRecording();
}
};
2 changes: 2 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import { init as initGainsight } from "./lib/gainsight";
import { initDatadog } from "./lib/datadog";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
Expand All @@ -10,3 +11,4 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
);

initGainsight(window, import.meta.env.PUBLIC_APTRINSIC_APP_ID);
initDatadog();

0 comments on commit d4a14ba

Please sign in to comment.