Web SDK
Cendyn CRM Web SDK is easy to integrate with JS.
Basic Integration
Cendyn CRM Web SDK is easy to set up in your project. You only need to follow the following steps:
- STEP 1 - To import the library, add the following line in your project in order to include the Cendyn CRM Web SDK.
<script src="https://assets-cdn.pushtech.com/sdk/web/2.0/PUSHTECHWebSDK.2.9.0.min.js" type="text/javascript">
- STEP 2 - To init the SDK, add in your code at the beginning of execution the following lines of code
var pushSdk = new PUSHTechSDK(your_app_id, your_app_secret,user_id);
pushSdk.init().then(function(abilities){
// Correctly registered in Cendyn CRM Platform.
}).catch(function(){
// Registration failed in Cendyn CRM Platform.
});
*The function init() return a
Promise.
You can get your app_id and app_secret in your personal account of Cendyn CRM Platform in apps section, View App details. The user_id is optional but must be unic as it will make sure that you are not duplicating your contacts, you can use the email or any other identificator.
(Optional) The setOptions methods call before init function and allows to enable or disable the following parameters in the SDK
- enable_geolocation: If true, send the metric of geolocation when the init function is called. By default: false
- enable_heartbeat: If true, send a request to the Cendyn CRM server to check if the user is still in webpage. By default: false
Web push Notifications
In order to use Web Push notifications you need to use the lastest version of Cendyn CRM Web SDK, add Service Worker file and check if your app has active flag to manage Web Push Notifications.
Service Worker file:
It is needed to create the js file in the root of web page ( https://www.example.com/pushtech-sw.js) with the code below:
*The name of the file is
"pushtech-sw.js"
if the name is different it will not work.
importScripts('https://assets-cdn.pushtech.com/sdk/web/sw/1.0/sw.1.0.0.min.js');
Metrics
The Web SDK provides the functionalities to create specific Metrics to your users details. These metrics are specific for each user, no global users. When you create a metric the function will return a boolean value, if the result is "true" the metric have been created, in case it is "false" this means that the parameters of this function is wrong.
Create Geolocation metric:
pushSdk.createGeolocationMetric();
This metric will send the geolocation of the user.
Create User metrics
In the following table you will find all the metrics related to the user attributes and user activity.
pushSdk.createBirthdateMetric(new Date()); |
Date object with date of birth date. |
pushSdk.createCountryMetric("ES") |
String of the Country ISO code with 2 chars (ISO 3166-1 alpha-2) |
pushSdk.createCityMetric("Barcelona") |
String with the city name. |
pushSdk.createFirstNameMetric("John") |
String with the first name. |
pushSdk.createLastNameMetric("Doe") |
String with the last name. |
pushSdk.createLanguageMetric("ES") |
String of language in ISO-2 |
pushSdk.createGenderMetric(Gender.MALE) |
Gender Object (Gender.MALE or Gender.FEMALE); |
pushSdk.createEmailMetric("john.doe@example.com") |
String with the valid email. |
pushSdk.createPhoneNumberMetric("+xxxxxxxxxxx") |
String in E.123 format |
pushSdk.createLoginGenericMetric() |
When user login in your page. |
pushSdk.createLogoutGenericMetric() |
When user logout in your page. |
pushSdk.createUserIdMetric("xxxx") |
String with the username to use any user to login in your page. |
pushSdk.createSubscriptionToListMetric("xxxxxxxxxxxxxxxxxxxxxxx") |
String with the list id to subscribe contact to the list. (More info: https://www.cendyncrm.com/manager/lists) |
pushSdk.createUnsubscriptionFromListMetric("xxxxxxxxxxxxxxxxxxxxxxx") |
String with the list id to unsubscribe contact for the list. (More info: https://www.cendyncrm.com/manager/lists) |
pushSdk.createGDPRAcceptTerms() |
Use this metric when user accept your terms and conditions |
pushSdk.createMarketingConsent(value) |
Use this metric when user accept your marketing consent. The only accepted value is true o false |
pushSdk.createLinkTerms(link) |
Use this metric to send what link terms user accept. It is only accepted a string of a link of your Terms and conditions. |
pushSdk.createLinkPrivacy(link) |
Use this metric to send what link of Privacy user accepts. It is only accepted a string of a link of privacy policy. |
Create Social metrics
In the following table you will find all the metrics related to the user social activity.
pushSdk.createLoginFacebookMetric() |
When user login in Facebook. |
pushSdk.createLogoutFacebookMetric() |
When user logout in Facebook. |
pushSdk.createFacebookIDMetric("207336719452056") |
String with the user Facebook ID. |
pushSdk.createNumberOfFacebookFriendsMetric(100) |
Int number of the user facebook’s friends. |
pushSdk.createLoginTwitterMetric() |
When user login in Twitter. |
pushSdk.createLogoutTwitterMetric() |
When user logout in Twitter. |
pushSdk.createTwitterIDMetric("Cendyn CRM") |
String with the user Twitter ID. |
pushSdk.createNumberOfTwitterFollowersMetric(100) |
Int number of the user followers in Twitter. |
pushSdk.createLoginGoogleMetric() |
When user login in Google. |
pushSdk.createLogoutGoogleMetric() |
When user logout in Google. |
pushSdk.createGoogleIDMetric("+Pushtechnologies") |
String with the user Google ID. |
Create Custom metrics
pushSdk.createCustomMetric("CUSTOM_KEY", "VALUE", ValueType.STRING);
You can track any events by using custom metric method. The "createCustomMetric" function required three parameters:
- Custom Key: Use the same key of our custom fields created in the Cendyn CRM platform: https://www.cendyncrm.com/settings/custom_fields
- Value: Any object like String, Number, Boolean or Date (Date in ISO_8601, Example: 1990-01-01T00:00:00Z).
- ValueType: Specific type of value to be sent. If the value object is different of ValueType the metric will no be created. Types: STRING, NUMBER, BOOLEAN, DATE
Create Custom Counter metrics
pushSdk.createCounterCustomMetric("CUSTOM_KEY", Value);
You can track the number of times an event occurs. The "createCounterCustomMetric" function required Two parameters:
- Custom Key: It is needed a custom field with the type Number created in the Cendyn CRM platform: https://www.cendyncrm.com/settings/custom_fields. The valor passed will increment the total value of the custom field.
- Value: Only allowed number type.
Create Purchase metrics
Cendyn CRM Web SDK allows you to track every purchase it is made in your eCommerce.
For each product that have been added, removed, purchased, refunded or purchase failed you must created a Product object:
var product = new Product();
product.productId = "2302323232-2321323-2-23"; //required
product.name = "Ball"; //required
product.price = 10.5; //required
product.currency = "EUR"; //required
product.description = "Description product"; //optional
product.url = "https://www.example.com/products/1"; //optional
product.image_url = "https://www.example.com/products/1/image.jpg"; //optional
product.transaction_code = "_238974982_32_32"; //optional Transaction ID
If you need extra information for yours products, you can create variable products at: https://www.cendyncrm.com/manager/product_custom_fields and use it like product fields
ADD product in cart:
pushSdk.createAddProductInCartMetric(product);
Remove product from the cart:
pushSdk.createRemoveProductFromCartMetric(product);
Refund product purchase:
pushSdk.createRefundProduct(product);
Failed product purchase:
pushSdk.createPurchaseFailedMetric(product);
When the user purchase several products you should create an another object to add all products in one metric:
var products = new Products();
products.add(product1);
products.add(product2);
pushSdk.createPurchaseProductsMetric(products);
Send metrics
pushSdk.sendMetrics();
You can decide when to send metrics to the Cendyn CRM Platform. If you create metrics but never call this method the metrics will not be send to the server.
The metrics are stored in the browser localStorage, when you call this method it will automatically retrieved from localStorage and send it. The metrics will be updated in few seconds and you can visualize the changes in contact details section of Cendyn CRM Platform.