> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.personizely.net/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Using the Javascript SDK

Personizely exposes some Javascript methods to give you more flexibility in using it.


# Identify API

**ply.identifyVisitor(data)** - 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 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.

An example call:
```
window.ply.identifyVisitor({
  "email": "test@personizely.net",
  "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

To track custom goals using JS use the exampe below: 
**ply.trackGoal('%Event name%', %Goal value%)**

Event name - the name of the event (can be anything)
Goal value - goal value in the currency of you 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)

# Manual Widget Trigger

**ply.showWidget(id, suppressRules)**

You show up any widget using this method indifferently of the triggers it has assigned to it.

**id** - _integer_, the id of the widget
**suppressRules** - _boolean_, whether to suppress the widget rules
