refactor: read ADOBE_SCRIPTS_SRC from env
This commit is contained in:
@@ -4,3 +4,4 @@ CMS_ENVIRONMENT="development"
|
|||||||
CMS_URL="https://eu-graphql.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}"
|
CMS_URL="https://eu-graphql.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}"
|
||||||
CMS_PREVIEW_URL="https://graphql-preview.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}";
|
CMS_PREVIEW_URL="https://graphql-preview.contentstack.com/stacks/${CMS_API_KEY}?environment=${CMS_ENVIRONMENT}";
|
||||||
CMS_PREVIEW_TOKEN=""
|
CMS_PREVIEW_TOKEN=""
|
||||||
|
ADOBE_SCRIPT_SRC=""
|
||||||
@@ -2,22 +2,14 @@ import { env } from "@/env/server"
|
|||||||
|
|
||||||
import Script from "next/script"
|
import Script from "next/script"
|
||||||
|
|
||||||
const scriptScrs = {
|
|
||||||
// TODO: decide on naming and environments (development vs. test vs. staging etc)
|
|
||||||
development: "",
|
|
||||||
test: "https://assets.adobedtm.com/c1bd08b1e4e7/d64a7c1f5f17/launch-84c70d82a50c-staging.min.js",
|
|
||||||
production:
|
|
||||||
"https://assets.adobedtm.com/c1bd08b1e4e7/d64a7c1f5f17/launch-e56085bbe998.min.js",
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function AdobeScript() {
|
export default function AdobeScript() {
|
||||||
return (
|
return env.ADOBE_SCRIPT_SRC ? (
|
||||||
<>
|
<>
|
||||||
<Script
|
<Script
|
||||||
strategy="beforeInteractive"
|
strategy="beforeInteractive"
|
||||||
id="ensure-datalayer"
|
id="ensure-datalayer"
|
||||||
>{`window.datalayer = window.datalayer || {}`}</Script>
|
>{`window.datalayer = window.datalayer || {}`}</Script>
|
||||||
<Script src={scriptScrs[env.NODE_ENV]} />
|
<Script src={env.ADOBE_SCRIPT_SRC} />
|
||||||
</>
|
</>
|
||||||
)
|
) : null
|
||||||
}
|
}
|
||||||
|
|||||||
2
env/server.ts
vendored
2
env/server.ts
vendored
@@ -12,6 +12,7 @@ export const env = createEnv({
|
|||||||
NODE_ENV: z.enum(["development", "test", "production"]),
|
NODE_ENV: z.enum(["development", "test", "production"]),
|
||||||
PRINT_QUERY: z.boolean().default(false),
|
PRINT_QUERY: z.boolean().default(false),
|
||||||
REVALIDATE_SECRET: z.string(),
|
REVALIDATE_SECRET: z.string(),
|
||||||
|
ADOBE_SCRIPT_SRC: z.string().optional(),
|
||||||
},
|
},
|
||||||
emptyStringAsUndefined: true,
|
emptyStringAsUndefined: true,
|
||||||
runtimeEnv: {
|
runtimeEnv: {
|
||||||
@@ -24,5 +25,6 @@ export const env = createEnv({
|
|||||||
NODE_ENV: process.env.NODE_ENV,
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
PRINT_QUERY: process.env.PRINT_QUERY,
|
PRINT_QUERY: process.env.PRINT_QUERY,
|
||||||
REVALIDATE_SECRET: process.env.REVALIDATE_SECRET,
|
REVALIDATE_SECRET: process.env.REVALIDATE_SECRET,
|
||||||
|
ADOBE_SCRIPT_SRC: process.env.ADOBE_SCRIPT_SRC,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user