How to use the javascript API for SiteGainer

The object

You can always run the SiteGainer object in console to get a list of JS API functionality.


sitegainer // Returns list of functions

sitegainer.newPage

If you are using single page apps with libraries like react.js and node.js or for any other reason want to run SiteGainer dynamically, you can just run sitegainer.newPage();. This runs the same functionality as is run when page loads. It also cleans your DOM from any changes that SiteGainer had run before sitegainer.newPage(); is called.


sitegainer.newPage(); // Simulate a pageload

What happens:

1. Dynamically refreshes DOM from SiteGainer changes ( no reload and no effect on javascript binds )
2. Updates information about URL, user, DOM.
3. Checks audience for each active project based on updated information
4. Runs projects where audience is true
5. Sends pageview and events to SiteGainer and integrations

sitegainer.runProject([The project ID])

Run’s a specific project regardless if audience is true or not.


sitegainer.runProject('19191919') // Runs a specific project.

sitegainer.getActiveVariation([The project ID])

Get’s the active variation for a project. Useful for retrieving active variation after using sitegainer.runProject();.


sitegainer.getActiveVariation('19191919') // Runs a specific project.