Figure: Shared code on a site
You can use shared code on a site to, for example:
For more information about shared code, see:
Both shared code and modifications allow you to run new code on a site. Which solution is right for you depends on what kind of code you want to run and what you want to achieve with that code.
Do not use shared code to programmatically inject HTML into a page, since the Frosmo Platform cannot track such content for clicks, displays, and true displays. If you want to use HTML, create a modification instead.
The process for creating and executing shared code flows as follows:
When a trigger fires on the page, Frosmo Core executes the shared code bound to the trigger, if any.
This can happen even before the scripts are fully initialized, since a trigger can be bound to an event that occurs before the initialization completes.
The following figure shows the data flow for shared code, from creating the code in the Control Panel to executing the code on the page.
Figure: Data flow for shared code (click to enlarge)
Shared code is effectively the first Frosmo feature to get initialized on a page. In other words, Frosmo Core executes shared code (without triggers) before initializing most other features, including triggers, modifications, and context.
For executing a piece of shared code, Frosmo Core automatically wraps the code inside an immediately invoked function expression (IIFE). This has the added advantage of preventing the variables in the code from leaking into the global scope.