Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App router migration rollbar script #1118

Merged
2 changes: 2 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Metadata } from 'next';
import GoogleTagManagerScript from '../components/head/GoogleTagManagerScript';
import RollbarScript from '../components/head/RollbarScript';

// Nextjs automatically includes for each route two default meta tags, charset and viewport
// https://nextjs.org/docs/app/building-your-application/optimizing/metadata#default-fields
Expand All @@ -22,6 +23,7 @@ export default function RootLayout({
but sending an event using sendGTMEvent requires an object rather than a list of arguments so the current gtag api function would need to be adapted
*/}
<GoogleTagManagerScript />
<RollbarScript />
{children}
</body>
</html>
Expand Down
7 changes: 6 additions & 1 deletion components/head/RollbarScript.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Script from 'next/script';

const RollbarScript = () => {
return (
<script
// eslint-disable-next-line @next/next/no-before-interactive-script-outside-document
<Script
id="rollbar"
strategy="beforeInteractive"
dangerouslySetInnerHTML={{
__html: `
var _rollbarConfig = {
Expand Down
2 changes: 2 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useEffect } from 'react';
import { Provider } from 'react-redux';
import CrispScript from '../components/crisp/CrispScript';
import GoogleTagManagerScript from '../components/head/GoogleTagManagerScript';
import RollbarScript from '../components/head/RollbarScript';
import Consent from '../components/layout/Consent';
import ErrorBoundary from '../components/layout/ErrorBoundary';
import Footer from '../components/layout/Footer';
Expand Down Expand Up @@ -83,6 +84,7 @@ function MyApp(props: MyAppProps) {
<meta name="viewport" content="initial-scale=1, width=device-width" />
</Head>
<GoogleTagManagerScript />
<RollbarScript />
<CrispScript />
<ThemeProvider theme={theme}>
<CssBaseline />
Expand Down
2 changes: 0 additions & 2 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { AppType } from 'next/app';
import Document, { Head, Html, Main, NextScript } from 'next/document';
import * as React from 'react';
import OpenGraphMetadata from '../components/head/OpenGraphMetadata';
import RollbarScript from '../components/head/RollbarScript';
import createEmotionCache from '../config/emotionCache';
import { MyAppProps } from './_app';

Expand All @@ -26,7 +25,6 @@ export default class MyDocument extends Document<NewRelicProps> {
rel="stylesheet"
/>
<OpenGraphMetadata />
<RollbarScript />
</Head>
<body>
<Main />
Expand Down
Loading