Conditionally include dataLayer object based on active theme

Created on 13 March 2024, 3 months ago

I had been running into an issue on a site where I have two public themes: one for the standard site and one for Google AMP β†’ . AMP's specifications don't allow for inline scripts, so I wanted to remove the dataLayer object from any page with the AMP theme active. I didn't find a way to do that with a hook (I tried a theme-specific hook_datalayer_alter() and hook_page_attachments_alter() to clear out the script data, but that still leaves an empty <script> tag), so instead, I added an option to the module's settings form through which you can specify on which themes you'd like the dataLayer object to be included. If no themes are selected, then the object is included on all themes.

Not sure if this will be of use to anyone else, but thought I would contribute it in case it is. Also happy to hear alternative suggestions if there are better ways to go about this. :)

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States KurtTrowbridge

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024