Introduction

Zinrelo loyalty rewards program can be integrated on your website by setting up the basic integration and authentication Javascript and then setting up the purchase tracking API.

In this document, we will walk you through the basic integration and authentication snippet in detail. The target audience for the document is the technical developer responsible for making code changes to your website.

Here is a video to guide you through integrating the Basic Integration Snippet:

If you are looking for an overview of integrating Zinrelo on your website, please see this document Getting Started with Zinrelo Integration. If you are using one of the pre-integrated shopping carts like Magento or Shopify, you do not have to do this step separately.

The basic integration and authentication snippet serves two purposes -

  • It passes the information of the user logged-in on your website to Zinrelo so that Zinrelo can authenticate the user, initiate a session and log the user into the loyalty program
  • This snippet also deploys different resources like the all.js javascript file and other scripts necessary to enable the loyalty dashboard and functions required for the loyalty program.

Where to find the snippet?

A customized basic integration and authentication code snippet for your account is available in your Zinrelo Admin Console in the ‘General’ tab under ‘Integration’.

How to include the snippet?

Add the snippet into the HEAD section of your website page template so that this snippet appears on ALL pages of your website. The JavaScript snippet looks like this:

<script type="text/javascript"> 

window._zrl = window._zrl || [];

var init_data = {
'partner_id' : '22ee49123b',
/*REQUIRED: Partner ID*/

'email' : 'useremail@gmail.com',
/*REQUIRED: When User is Logged in.For Non-Logged in users,
pass an empty string ('')*/

'name' : 'User Name',
/*REQUIRED: When User is Logged in.For Non-Logged in users,
pass an empty string ('')*/

'user_id' : 'Unique-user-ID',
/*REQUIRED: When User is Logged in.For Non-Logged in users
and guest users who DO NOT have an account, pass an empty
string ('')*/

'ts' : 'Current TimeStamp in epoch format',
/*REQUIRED : Timestamp in epoch format'*/

'access_token' : 'acafb9c8d189b55671b5956bd75b33ee2e982b89ef42f3b26421f6d8f7fe4872'
/*REQUIRED : 'SHA256 hash of the string formed by concatenating
- user_id, email,partner_id, api_key and ts - in the same
order as mentioned' */

};

_zrl.push( [ 'init' , init_data ] );

</script>

<script src="//cdn.zinrelo.com/js/all.js" type="text/javascript"></script>

Populate the following fields dynamically: ‘partner_id’, ‘email’, ‘name’, ‘user_id', 'ts', 'access_token' . These fields contain end-user information – email, user full name and user_id – and the rest of the fields - 'ts' and 'access_token' are required for ensuring the security and integrity of the data passed.

For a logged in user, these must be filled dynamically wherever available. For a guest/non-logged in user, you can simply pass the 'partner_id' and pass empty string ('') for the rest of the values.


If only the user_id field is not available to Zinrelo on a particular page, it is still assumed that the customer is not logged in to the website and will be logged out of the loyalty program too.

Shown below is the detailed description of the fields to be populated dynamically. All fields are required and must be populated for the loyalty rewards program to work.

  • partner_id : This is an alpha-numeric value assigned that uniquely identifies your account in Zinrelo. You can find your Partner ID in Zinrelo Admin Console > General > Settings section . If you have any trouble getting your Partner ID, please contact our Customer Success Manager or email support@zinrelo.com
  • email : This is the email address of the user who is logged in to your website e.g - johndoe@gmail.com . Zinrelo uses this email address to identify a user record in Zinrelo database. It is used to associate loyalty transactions and to communicate with and re-engage the user.
  • name : This is the full name of the user who is logged in to your website. This information is used to address the user on the loyalty rewards dashboard and to include in the email templates sent to the user.
  • user_id : This is the unique identifier of the user in your database. Zinrelo uses this ID as an additional identifier for the user.
  • ts : This is the current timestamp in unix epoch format. For e.g 1602058996.
  • access_token : This is the SHA256 hash of the string formed by concatenating - user_id, email, partner_id, api_key and ts - in the same order as mentioned. This will be string with 64 characters. When Zinrelo receives all the above values , it generates its own SHA256 hash with the API key from your account and matches it with the access_token you passed. This is to verify the authenticity of the data.
    - In order to generate access_token, you will need an API key. You can find your API Key in Zinrelo Admin Console > General > Settings section just below the Partner ID. If you have any trouble implementing the logic to generate access_token, please reach out to support@zinrelo.com
    - Please note that you do not share your API key with anyone or anywhere. It should be used only in the backend systems.

Note : Since you would never want to expose your API Key on the frontend, you will need to generate the access_token at the backend and relay it over to the frontend so that it can be passed in the Zinrelo javascript snippet.

Common Mistakes

Here are some common mistakes in including the Basic Integration Snippet:

  • Partner ID is copied as-is from this document: The partner_id field is a unique key generated by Zinrelo to identify a Client. Please confirm that your partner_id is correct. If you are copying code from the Zinrelo Admin Console, the partner_id will be correct. If you are copying as-is from this document, the partner_id will be wrong.
  • Integration snippet is copied as-is: The fields must be filled dynamically from the information available on the website. Therefore, a developer with some technical skills is required to complete this task. It is not a mere copy and paste.
  • All.js code is not copied onto the website: Zinrelo uses a Javascript called all.js. This script must be included in the snippet.

    <script src = “//cdn.zinrelo.com/js/all.js” type=“text/javascript”>

    However, please do not look at the insides of all.js and copy that code to your website. Some variables will not be available and the script will fail.
  • Incomplete information is passed: For example, the user_id field is passed but email and full name are not passed. This causes the email engine which engages the user to fail. If all the information is not available, the program will not work.

Once you have added the basic snippet on your website, the next step is to set up the purchase tracking API

Did this answer your question?