JS API

5min
personizely exposes some javascript methods to give you more flexibility in using it identify api ply identifyvisitor(data) this method returns a promise data object , containing information about the visitor and custom fields values the object can have the following properties email string , a valid email address firstname string , visitor's first name lastname string , visitor's last name phone string , visitor's phone number companyname string , visitor's company name companytitle string , visitor's company title marketingconsent boolean , visitor's marketing consent status privacyconsent boolean , visitor's privacy consent status address string , visitor's address bio string , visitor's bio customfieldvalues object , visitor's custom field's values the custom field values object is an object where the keys are the custom fields id's which can be found on the settings page and the values are the values of the respective fields for the current visitor for radio and select field types you need to make sure that the choice options are valid ones, so if you have a field named "gender" with 2 options male, female, you won't be able to save a different value than one of those two values the checkbox type fields should receive a boolean value the number type fields should receive a numeric value example ply identifyvisitor({ "email" "john\@example com", "firstname" "john", "lastname" "doe", "phone" "+1665599555", "companyname" "personizely", "companytitle" "ceo", "marketingconsent" true, "privacyconsent" true, "address" "5th avenue", "bio" "my bio", "customfieldvalues" { "1" "male" } }) goal tracking api ply trackgoal(eventname, value) this method is used to track custom goals eventname string , the name of the event (this should be the name of an existing goal in your personizely website settings) value number , goal value in the currency of your website for example, to track a purchase worth $100 on your site, you can use the following code on your thank you page ply trackgoal('purchase', 100) custom event tracking api ply trackevent(eventname, value) this method is used to track custom events eventname string , the name of the event (this can be any arbitrary event name or the name of an existing goal in your personizely) value number , event value in the currency of your website (optional) for example, to track an add to cart event worth $29 on your site, you can use the following code when a visitor adds a product to the cart ply trackevent('add to cart', 29) widgets api ply showwidget(id, suppressrules, stepid) this method is used to show up any widget regardless of the triggers it has assigned to it id integer , the id of the widget suppressrules (optional) boolean , whether to suppress the widget rules stepid (optional) int , the id of the step to open the widget on use this if you need to skip a step or reopen the widget on a specific step campaigns api ply runcampaign(id) this method is used to run a campaign manually id integer , the id of the campaign returns the displayed variation or null/undefined if the user falls into the control group for full stack campaigns, you can retrieve the enabled features with variation getfeature(featurekey) featurekey string , the key of the feature as defined when the feature is created returns the feature to get a parameter of a feature, use this feature getparametervalue(key) key string , the key of the parameter example const variation = ply runcampaign(3000000) if (variation) { const cartfeature = variation getfeature('cart') if (cartfeature isenabled()) { const message = cartfeature getparametervalue('message') alert(message) } } else { // control } website data api this method is used to set website data the method can be called in two ways 1st way ply setdata(data) data object, an object containing key value data pairs, the values will be merged with the existing data object 2nd way ply setdata(key, value) key string , the name of the key to be written to the data object value mixed, the value, can be string, boolean, number, null for example, to add cart details to your website data you can use ply setdata('cartsize', 5) to set a single value or ply setdata({cartsize 5, cartvalue 99}) to set multiple values at once