-
SummaryI have a Gatsby project where several users can create landing pages with Strapi CMS. And I need to put on this pages different Google Tag Manager scripts by ID, that coming from Strapi. How can i get page context from PS. I'm currently using Relevant informationEnvironment (if relevant)npmPackages: File contents (if changed)
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I think the |
Beta Was this translation helpful? Give feedback.
-
The marked answer here mentions I wrote a quick guide for an alternative way that doesn't use I hope this isn't considered self promotion, just trying to update this thread as I found it while trying to do the class adding myself! |
Beta Was this translation helpful? Give feedback.
-
Bit late to the party, I know. A solution that I came up with was manually reading the relevant const pageDataFile = path.join(process.cwd(), "public", "page-data", (pathname === "/" ? "index" : pathname), "page-data.json");
const pageContext = JSON.parse(fs.readFileSync(pageDataFile, "utf8")).result.pageContext; Just make sure to pass the |
Beta Was this translation helpful? Give feedback.
I think the
onRenderBody
method isn't suitable for what you want. You don't have access to the pageProps or the ability to run any graphql queries. It would be much simpler to use react-helmet. You can put this into your pages, get the information from the graphql data and let react helmet build up the correct head components. This will also be statically generated as well 👍