Skip to content

chore: only load analytics scripts in production or staging environments #7644

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

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function MyApp({ Component, pageProps }) {
} = pageProps;

const router = useRouter();
const { BUILD_ENV } = process.env;

useEffect(() => {
const handleRouteChange = () => {
Expand Down Expand Up @@ -138,50 +139,53 @@ function MyApp({ Component, pageProps }) {

<link rel="apple-touch-icon" href="/assets/icon/icon.png" />

{process.env.BUILD_ENV !== 'production' ? (
{BUILD_ENV === 'production' ? (
<>
<link
rel="preload"
as="script"
href="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
href="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
/>
</>
) : (
) : BUILD_ENV === 'staging' ? (
<>
<link
rel="preload"
as="script"
href="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
href="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"
/>
</>
)}
) : null}
</Head>

<MDXProvider>{getLayout(<Component {...pageProps} />)}</MDXProvider>

{process.env.BUILD_ENV !== 'production' ? (
{BUILD_ENV === 'production' ? (
<>
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script src="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script src="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script
src="https://alpha.d2c.marketing.aws.dev/client/loader/v1/d2c-load.js"
src="https://d2c.aws.amazon.com/client/loader/v1/d2c-load.js"
defer
></script>
</>
) : (
) : BUILD_ENV === 'staging' ? (
<>
{/* eslint-disable-next-line @next/next/no-sync-scripts */}
<script src="https://a0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script src="https://aa0.awsstatic.com/s_code/js/3.0/awshome_s_code.js"></script>
<script
src="https://d2c.aws.amazon.com/client/loader/v1/d2c-load.js"
src="https://alpha.d2c.marketing.aws.dev/client/loader/v1/d2c-load.js"
defer
></script>
</>
)}
<link
href="https://prod.assets.shortbread.aws.dev/shortbread.css"
rel="stylesheet"
></link>
) : null}

{BUILD_ENV === 'staging' || BUILD_ENV === 'production' ? (
<link
href="https://prod.assets.shortbread.aws.dev/shortbread.css"
rel="stylesheet"
></link>
) : null}
</>
);
}
Expand Down
11 changes: 7 additions & 4 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ export default class MyDocument extends Document {
httpEquiv="Content-Security-Policy"
content={getCspContent(this.props)}
/>
<script
src="https://prod.assets.shortbread.aws.dev/shortbread.js"
defer
></script>
{process.env.BUILD_ENV === 'production' ||
process.env.BUILD_ENV === 'staging' ? (
<script
src="https://prod.assets.shortbread.aws.dev/shortbread.js"
defer
></script>
) : null}
</Head>
<body>
<Main />
Expand Down
Loading