Javascript API

 

Get a list of the JS API functions

Enter sitegainer and hit Enter in the console to get a list of JS API functionality.

sitegainer // Returns list of functions

 

mceclip0.png

 

debug()

If you turn on debug mode Symplify will output complete logs and objects in the console

sitegainer.debug(1); // Turn on debug mode 
sitegainer.debug(0); // Turn off debug mode 

 

forceProject()

If you want to run a project regardless if the audience is true use this snippet inside of the Symplify variation code or in your own environment as long as the Symplify script has loaded.

sitegainer.forceProject([The project ID]); // Add your project ID here 

 

getActiveProjects()

Get's an array of active projects. 

sitegainer.getActiveProjects();

 

getActiveVariation()

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

sitegainer.getActiveVariation([The project ID]);

 

getCTMData()

Get's data that would be sent to CallTrackingMetrics if implemented.

 

getGeo()

In order to retrieve the visitors IP address or geodata, just use this simple snippet:

sitegainer.getGeo([key]); // Enter a key to get the value

Example keys and values (keys in bold):

as:"AS2119 Telenor Norge AS"
city:"Stockholm"
country:"Sweden"
countryCode:"US"
isp:"Bredbandsbolaget AB"
lat:59.3333
lon:18.05
org:"Bredbandsbolaget AB"
query:"213.115.103.83"
region:"AB"
regionName:"Stockholm"
status:"success"
timezone:"Europe/Stockholm"
zip:"173 11"

 

getSupressedFields()

Get's an array of suppressed elements for Visitor Recording projects.

sitegainer.getSuppressedFields(); // array of supressed elements

 

newPage()

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

sitegainer.newPage();

What happens:

1. Dynamically refreshes DOM from Symplify 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 Symplify and integrations

 

optOut()

If you need to temporarily prevent Symplify from running projects you can use our function below to opt-out. You can also add ?sg_optout ( or #sg_optout / &sg_optout ) in the URL and hit Enter. This will load the page without Symplify.

This sets a session cookie that will be removed when the tab and/or browser is closed. You can also remove the sg_optout cookie to exit this mode.

sitegainer.optout(1); // Turn on optout 

 

previewProject()

Opens up a preview for a specific project and variation.

sitegainer.previewProject([project id], [variation id]]); // Enter project ID and variation ID 

 

pushGoal()

Symplify offers standardised custom goals for general measuring points. Using these you don't have to create any push goals in your project. They will be created automatically and will show up in the statistics when data is registered. Please make sure that Symplify has loaded before calling these to avoid errors:

if(sitegainer) {
	sitegainer.pushGoal("{You goal id}");
} else {
  document.addEventListener("sitegainer-loaded", function(e) {
  	sitegainer.pushGoal("{You goal id}");
  });
}

Examples of standard goals to use;

sitegainer.pushGoal("order"); // Register visitors that put an order
sitegainer.pushGoal("checkout"); // Register visitors who went to checkout
sitegainer.pushGoal("addtocart"); // Register visitors that added an item to cart
sitegainer.pushGoal("cartpage"); // Register visitors that went to cart page if different than checkoutpage
sitegainer.pushGoal("productpage"); // Register visitors that went to product page
sitegainer.pushGoal("product-listing"); // Register visitors that went to the product listing
sitegainer.pushGoal("homepage"); // Register visitors that went to the home page
sitegainer.pushGoal("searchpage"); // Register visitors that went to the search page
sitegainer.pushGoal("searched"); // Register visitors that used search
sitegainer.pushGoal("loggedin"); // Register visitors that logged in

 

runProject()

Run's a specific project

sitegainer.runProject([The project ID]); // Runs a specific project.

 

setGeo()

Sets IP or geodata for the current user.

sitegainer.setGeo([key], [value]); // Enter key and set a value.

Example keys and values (keys in bold):

as:"AS2119 Telenor Norge AS"
city:"Stockholm"
country:"Sweden"
countryCode:"US"
isp:"Bredbandsbolaget AB"
lat:59.3333
lon:18.05
org:"Bredbandsbolaget AB"
query:"213.115.103.83"
region:"AB"
regionName:"Stockholm"
status:"success"
timezone:"Europe/Stockholm"
zip:"173 11"

 

spaCheck()

Deprecated

 

transaction()

See How to track visitors e-commerce transactions

 

userdata()

See How to use the "userdata" object

 

 

 

Was this article helpful?
0 out of 0 found this helpful