Salesforce Getting Started

Learn more about installing the Pyze Salesforce Smart SDK, initializing it, using timed and custom events.

1. Get a Pyze App Key

See instructions to get a Pyze App Key for your new app

2. Initialize

Add initialization code into your salesforce lightning component, aura application or visual force pages.

Build and Go!

You have enabled all screen flow funnels, loyalty, cohort and churn analysis, Intelligence data explorations, built-in events, auto segmentation, and much more. Use your app with the Pyze SDK and you should see data on growth.pyze.com.

In the following sections, you can add app-defined and timed events.

4. Add events

Add events to your Salesforce app. A comprehensive overview of curated, app defined, timed and built-in events is available under Events in the api & events.

Pyze Salesforce Developer Center has links to Pyze Documentation and api. Check back frequently for updates and contact us at contact@pyze.com if we can improve this page in anyway or if you have suggestions.

Install

Get Pyze App Key

Get a Pyze App Key (PAK) from growth.pyze.com

1. Login to growth.pyze.com

Every app is uniquely assigned a Pyze App Key (PAK), a 22 character app specific key, which you obtain from growth.pyze.com after logging in with your email and password. If you have not signed up for Pyze, you can Get Pyze here first.

Login to growth.pyze.com

2. Add a new app

  • To add an application to the Pyze platform, begin by selecting Settings from the Navigation Pane.
  • Under the Apps Tab, click the Add App+ button at the top right of the window.
  • Enter the App Name and Appstore URL (if available), Platform (iOS, Android, Web/SaaS, tvOS, watchOS) and select your Timezone.
  • Copy Pyze App Key from your newly added app

Navigate to the newly added app’s settings by ensuring the app you just added is selected from the dropdown menu and copy the Pyze App Key (DmPTFdslRjObk1-ZlXQDVQ in this example).

Initialize

Initialize Pyze for Salesforce.

The instructions on this page assume you have obtained the Pyze App Key for your project. If not, visit Getting Started Web Guide to get the Pyze App key.

  1. Download the PyzeSalesfore js library from this link
  2. Upload the PyzeSalesforce js library to static resources.
  3. Add https://unifiedcollector.pyze.com into CSP(Content Security Policy) Trusted Sites as defined in this link
  4. Import the PyzeSalesforce js into your Salesforce lightning component, aura appication or a visual force page as shown below.

Lightning Component integration

/* import the PyzeSalesforce library into the lightning component*/
import pyzeSalesForce from '@salesforce/resourceUrl/PyzeSalesforce';


/* Load the script and initialize */
renderedCallback() { // invoke the method when component rendered or loaded
   Promise.all([
      ...
      loadScript(this, pyzeSalesForce), // Pyze SDK script
   ])
   .then(() => { 
      Pyze.initialize("YOUR_PYZE_APP_KEY"); // Initialize Pyze once library is loaded successfully!
   })
   .catch(error => {
      ...
   });
}

Check the link for more information about how to load js library inside a lighting web component.

Lightning Aura Component or Application integration

/* - import the PyzeSalesforce library into the lightning aura component or application 
   - Define a function to run after script loaded successfully! */
<ltng:require scripts="{!$Resource.PyzeSalesForce}" afterScriptsLoaded="{!c.initializePyze}" />

/* Initialize Pyze Salesforce SDK  once the library loaded successfully! */
initializePyze : function(component, event, helper) {
    Pyze.initialize("YOUR_PYZE_APP_KEY");
}

Check the link for more information about how to load js library inside a lighting aura component or application.

Visualforce component integration

/* - import the PyzeSalesforce library into the visualforce page */
<apex:includeScript value="{!$Resource.pyzeTrackingSnippet}"/>

/* Initialize Pyze Salesforce SDK  once the library loaded successfully! */
<script>
   Pyze.initialize("YOUR_PYZE_APP_KEY");
</script>

Check the link for more information about how to import js library into a visual salesforce page

Remember to replace “YOUR_PYZE_APP_KEY” with the Pyze App key you got from growth.pyze.com

Build and Go!

Add Events

See a detailed Events Overview here.

Pyze has made it easy for you to capture events. We support custom and timed events.

Custom Event Handling

We support custom events that can be used to track any event within the salesforce components and can be called with or without attributes. See postCustomEvent and postCustomEventWithAttributes method in the Pyze class (See here).

// Custom Event without Attributes
PyzeEvents.postCustomEvent("Blog Read");

// Custom Event with Attributes
// Create an object with key value pairs of custom attributes and post with postCustomEventWithAttributes

var attributes = {};
attributes["screen"] = "Home";
attributes["seconds spent"] = "50";

PyzeEvents.postCustomEventWithAttributes("Blog Read", attributes);

//Events with Attributes as Object
var attributes = {};
var address = {"city":"Redwood city","state":"CA","phone":{"home":{"area":"408", "prefix":"434", "linenumber":"5234"}}};
attributes["address"] = address;
PyzeEvents.postCustomEventWithAttributes('Blog Read', attributes)

Timed Events

Pyze has made it easy for you to capture duration between events. Pyze supports timed events using following API’s

  • startTimerForEvent - Use this API start timer for perticular event by passing the event name attribute.

  • postTimedEvent - Use this API to end timer and post the event with duration. This API accepts event name attribute. You can also pass attributes as additional parameter as shown in the example below


//Start timer for event
PyzeEvents.startTimerForEvent("Screen Load Time");

//Post timed event. 
//Note : The event name attribute for the `startTimerForEvent` and  `postTimedEvent` should match.
PyzeEvents.postTimedEvent("Screen Load Time");

//Post timed event API when you want to send additional attributes
var customAttributes = {};
customAttributes["device"] = "iMac";
customAttributes["location"] = "CA";
PyzeEvents.postTimedEventWithAttributes("Screen Load Time", customAttributes);

Dimensions

Dimensions are attributes that get attached to all events within a session. This is useful to have a standard set of attributes that change over time, and is simply a helper to accomplish this goal.

Dimensions are any key-value pairs that you attach to the initialize call. Create an object, and modify the initialize call to include this object.


var dimensions = {
  "department": "marketing",
  "role": "associate",
  "alpha": true
}

Pyze.initialize(pyzeAppKey, dimensions);

Any event sent during this session will include the dimensions as attributes

User Profiles

Pyze provides ways to segment data for each logged in user. You can use the following API’s to manage user profiles within your app.

setUserProfile

Use this API to set user profiles.

//Create Pyze Profile Attributes object
var pyzeProfileAttributes = {
   "email_id"        : "xyz@abc.com",
   "date_of_birth"   : "1984-06-01",
   "first_name"      : "John",
   "last_name"       : "Jacobs"
}
//Create Custom Profile Attributes object
var customProfileAttributes = {
   "age"       : 29,
   "pincode"   : "23200",
   "city"      : "XYZ"
}
//Call the setUserProfile API
PyzeIdentity.setUserProfile(userId,pyzeProfileAttributes,customProfileAttributes);

Following are the possible Pyze user profile attributes.

Pyze User Profile Field Name Data Type/Description
background (string) User background, biography or historical data
country (string) Country codes must be sent in the ISO-3166-1 alpha-2 standard.
current_location (object) Format: {“longitude”: -33.991894, “latitude”: 25.243732}
date_of_first_use (date at which the user first used the app) String in ISO 8601 format or in yyyy-MM-dd’T’HH:mm:ss.SSSZ format.
date_of_last_use (date at which the user last used the app) String in ISO 8601 format or in yyyy-MM-dd’T’HH:mm:ss.SSSZ format.
date_of_birth (date of birth) String in format “YYYY-MM-DD”, example: 1984-06-01.
email_id (string) Email Id
email_subscribe (string) Acceptable values are “opt_in” (explicit approval to receive email messages), “opt_out” (explicit denial to email messages), and “subscribed” (neither opted in nor out).
email_hard_bounced Automatically updated when a hard bounce occurs (true or false)
email_spam_reported Automatically updated when a user marks your email as spam, via the ISP (true or false)
facebook_id facebook ID
first_name (string) User’s First name
gender (string) “M”, “F”, “O” (other), “N” (not applicable), “P” (prefer not to say) or “U” (unknown).
home_city (string) User’s Home City
image_url (string) URL of image to be associated with the user
language (string) Require language to be sent in the ISO-639-1 standard.
last_name (string) User’s Last Name
marked_email_as_spam_at (string) Date at which the user’s email was marked as spam. Must be in ISO 8601 format or in yyyy-MM-dd’T’HH:mm:ss.SSSZ format.
phone (string) Phone number
push_subscribe (string) Available values are “opted_in” (explicitly registered to receive push messages), “unsubscribed” (explicitly opted out of push messages), and “subscribed” (neither opted in nor out).
push_tokens Array of objects with app_id and token string. You may optionally provide a device_id for the device this token is associated with, e.g., [{“app_id”: App Identifier, “token”: “abcd”, “device_id”: “optional_field_value”}]. If a device_id is not provided, one will be randomly generated.
time_zone (string) Time Zone’s must be sent as per IANA Time Zone Database (e.g., “America/New_York” or “Eastern Time (US & Canada)”). Only valid values will be respected.
twitter_id Twitter ID

updateUserProfile

To update user profile attributes which are already set, use the following api.

Note : Do not call this api before calling setUserProfile.

//Create Pyze Profile Attributes object
var pyzeProfileAttributes = {
   "email_id"        : "xyz2@abc.com",
   "date_of_birth"   : "1984-07-01",
   "first_name"      : "John M",
   "last_name"       : "Jacobs"
}
//Create Custom Profile Attributes object
var customProfileAttributes = {
   "age"       : 29,
   "pincode"   : "232001",
   "city"      : "XYZ2"
}
//Call the updateUserProfileAttributes API
PyzeIdentity.updateUserProfile(pyzeProfileAttributes,customProfileAttributes);

resetUserProfile

This API is used to reset the user. Call this when you want to remove user from the device.

PyzeIdentity.resetUserProfile(); 

User Privacy

Pyze provides APIs to allow end-users to Opt out of Data Collection and also instruct the Pyze system to forget a user’s data.

setUserOptOut

Allows end-users to opt out from data collection. Opt-out can be toggled true or false.

Pyze.setUserOptOut(true) 

To resume user data collection set value to false

Pyze.setUserOptOut(false) 

deleteUser

Allows end-users to opt out from data collection and delete the user in the Pyze system. We recommend you confirm this action as once a user is deleted, this cannot be undone.

Pyze.deleteUser(true)