Js mini

Web SDK


PUSHTech™ Web SDK is easy to integrate with JS.


Basic Integration

PUSHTechWebSDk is easy to set up in your project. You only need to follow the following steps:

  • STEP 1 - Download and add to your project the library "PUSHTechWebSDK.1.4.0.min.js".
  • STEP 2 - To import the library, add the following lines in your project to include the PUSHTechWebSDK.

<script src="PUSHTechWebSDK.1.4.0.min.js" type="text/javascript">

  • STEP 3 - 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(function(success) {
    if (success) {
      // Register Correctly in PUSHTech Platform.
    } else {
      // Register failed in PUSHTech Platform.
    }
  });

You can get your app_id and app_secret in your personal account of PUSHTech 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.

Metrics

The Web SDK provides the functionalities to create specific Metrics to your users details. This metrics are specific for each user, no global users. When you create a metric the function return a boolean value, if the result is "true" the metric have been created, in case it is "false" this means the parameters of this function 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.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("102092")

String with the username to use any user to login in your page.

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("PUSHTechCloud")

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("TYPE", "SUBTYPE", "VALUE", ValueType.STRING);

You can track any events by using custom metric method. The "createCustomMetric" function required four parameters:

  • Type: String to classify the custom metric.
  • Subtype: String to describe the custom metric.
  • Value: Any object like String, Number, Boolean or Date.
  • ValueType: Specific type of value to be sent. If the value object is different of ValueType the metric will no be created.

Create Purchase metrics

PUSHTechWebSDK allows you to track every purchase it is made in your eCommerce.

For each product that have been added or removed from the user cart you should created Product object:

var product = new Product();
product.productId = "2302323232-2321323-2-23";
product.name = "ball";
product.price = 10.5;
product.currency = "EUR";

ADD product in cart:

pushSdk.createAddProductInCartMetric(product);

Remove product from the cart:

pushSdk.createRemoveProductFromCartMetric(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 PUSHTech™ 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 PUSHTech™ Platform.