Streaming live at 10am (PST)

Custom head code in individual pages

I have found several posts asking for custom head code per page but none with a solid solution, so I’m hoping I have just missed the aha moment post somehow …

Our site represents franchisees, each of which has their own location page, and many of them want to add analytics tags to ONLY their pages, not the whole site. … and I am stumped on how to add custom code to just their pages within the /head tag and just before the /body tag.

I’m OK using something like this in the global /head / body areas, but have yet to be able to make it work…

if (window.location.pathname == ‘RELATIVE-PATH-TO PAGE’)

Suggestions appreciated

Thank you

Custom code can be added to the head of the document on any particular page. That option does not exist on collection items since there is only one collection template.

Thank you.
I should have clarified that we do need to do this on collection pages.

I am sure hoping someone has found a workaround for something similar.
We can’t be the only webflow users wanting to do something like this.

Theoretically, I should be able to do this with an IF statement in the global head code so it renders based on the URL, no? LIke pwily’s suggestion here?

You can run code that adds features or additional resources to a page based on the URL with JavaScript. You just have to write it or hire someone to code it for you.

@WJM - you could also possible include a field or a field in combination with a toggle field to allow individual locations to insert their own UA id on their page.

For example you could have a text field called Google Analytics ID where users can insert a value. Then in the custom code for the page you can insert that variable and use JS to insert the value dynamically in the analytics code.

Does that make sense / help?

I forgot about the toggle option … something like that might work.
I’ll take a stab at it, but won’t the Google JS load with an empty value for pages with the field ‘off’?

Thank you!

Depending on what other dynamic content you need to load on each franchisee’s landing page, could you build those as regular pages with collection inserts instead of using a collection template? Then you could have the head code available natively.