Load script for any page when logged in to the Optimizely CMS

I would like a small JavaScript to be executed every time a content manager loads a page while being logged in (i.e. not for pages rendered for end users). I have tried to do this via a module (module.config + JS file with and without Dojo) both under modules\_protected and in root/wwwroot\ClientResources). I (believe) that I got this working for pages in "Edit", but not for "Dashboard", "Reports", "Settings", "Add-ons" etc. I have asked a number of LLMs for advice but so far with no luck.

I have an alternative solution based on a middleware that seems to work. However, this feels a bit like a hack and I cannot help to think that there must be a better, more Optimizely based way to do this. Any suggestions on how to go about appreciated. 

We are using CMS 12.

#343003
Jul 10, 2026 13:21

You want the script rendered when editors views the public pages? Or only when they browse any parts of the CMS UI?

#343006
Jul 11, 2026 1:38

Hi Anders,

If you want to follow a more Optimizely-based approach rather than using middleware, I would suggest exploring a protected Shell module with a client module initializer. Optimizely documents module initializers as the extension point for running JavaScript when a client module is initialized:

https://docs.developers.optimizely.com/content-management-system/docs/adding-a-module-initializer

Configure the client module to run after the Optimizely Shell module rather than depending only on the CMS module. The CMS dependency is primarily associated with the edit interface, whereas the Shell module may provide a broader loading context for the authenticated Optimizely UI.

In module.config you could try:

<moduleDependencies>
  <add dependency="Shell" type="RunAfter" />
</moduleDependencies>

You can then register the JavaScript as a required client resource and execute the logic from the module initializer’s initialize() method.

Since the Optimizely UI behaves as a single-page application, the initializer will normally run when the module is loaded. If the script must execute after every internal navigation, you may additionally need to listen for route or view changes.

I would validate the Shell dependency across Dashboard, Reports, Settings and Add-ons, as the initializer documentation explains the extension mechanism but does not explicitly guarantee that one module will load in every authenticated view.

 

#343030
Edited, Jul 14, 2026 15:27
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.