How Xtremepush web SDK works?

Integrating web SDK

Xtremepush web SDK can be integrated with the website by adding a js tracking code that look like this:

(function(p,u,s,h,e,r,l,i,b) {p['XtremePushObject']=h;p[h]=function(){
     (p[h].q=p[h].q||[]).push(arguments)};i=u.createElement('script');i.async=1;
     i.src=s;b=u.getElementsByTagName('script')[0];b.parentNode.insertBefore(i,b);
})(window,document,'https://cdn.webpu.sh/APP_KEY/sdk.js','xtremepush');

 The above code does 4 main things:

  1. Creates a <script> element that starts asynchronously downloading the sdk.js JavaScript library from https://cdn.webpu.sh which is our CDN
  2. Initializes a global xtremepush function (called the xtremepush() command queue) that allows you to schedule commands to be run once the sdk.js library is loaded and ready to go.

The xtremepush() function is a command queue because rather than executing the commands it receives immediately, it adds them to a queue that delays execution until the sdk.js library is fully loaded.

This pattern allows developers to use the xtremepush() command queue without having to worry about whether or not the sdk.js library has finished loading. It provides a simple, synchronous-looking interface that abstracts away most of the complexities of asynchronous code.

 

SDK behavior when loaded

Our SDK operates in a fully asynchronous fashion and does not affect existing javascript code.

It uses several type of API requests to send data to our servers. All the API requests are going through HTTPS and are being sent asynchronously.

All the communication between client code and SDK is happening through the xtremepush() command queue.

 

User identification & data collection

In order for our SDK to persist client information between different page views and sessions we store client ID in cookie called "_xpid". We also store a local storage item called "xtremepush" to keep information about the client.

During the first page load for the new user an API request will be send to Xtremepush server to register the client. 

During the following page loads an API request will be sent only if some of user's information were changed, such as user language.

 

Webpush notifications

In order to support Chrome and Firefox webpush notifications our SDK registers the service worker.

Our service worker implements following callbacks:

  • install
  • activate
  • push
  • notificationclick
  • notificationclose

It doesn't implement anything that could affect application usage, such as providing additional network cache.

Our SDK also adds a reference to manifest.json to the head of the page if missed. 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.