Developer Knowledge Required.
The Retainly Tracking Script is very useful for SaaS products and for those bloggers who offer a membership module. The tracking script automatically tracks new Signups and adds them as contacts in your Retainly Default List. The script can also track events triggered by your customer's behavior which can be used for Real Time Behavioural Marketing.
Login to your Retainly application and navigate to Settings, where you will find your own JS Tracking Script. Below is the sample Script.
- <script>
- window.retainlySettings = {
- app_id: "589ae9dd63321",
- company: "Name of the company",
- email: "[email protected]",
- signedup_at: "2017-02-22",
- plan: "Premium"
- };
- </script>
Elements of this Script
1. app_id: Is your unique id which is autogenerated by Retainly. Do not change it.
2. company: It is an optional field that can help you to group your contacts. You can change the value field. If you use server variables, you can use something like company: "<?php echo $company;?> "
3. email: Email Id of the user that you willing to track. This is a mandatory field. if you use server variable, you can use like email: "<?php echo $logged_mail;?>"
4. singedp_at : This is optional, but can be useful to plan your drip based on the signup date on your app/website. It is the value of the variable to denote when the user is created. Server Variable can be used as signedup_at: "<?php echo $singedupdate;?>"
5. plan: Another optional field which helps you to capture the plan or package selected by your customer, and can be changed as per your need. Server variables can be used as plan: "<?php echo $plan; ?>"
The Script Function
The script below automatically tracks the page visits based on the user configuration.
You need to add this script as it is, in all your pages, ideally in your footer. And ensure the above script too has set before this
- <script>
- (function(){var w=window;var d=document;var r=function(){r.c(arguments)};r.q=[];r.c=function(args){r.q.push(args)};w.retainly=r;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://retainly.co/app/getjs/retainly/'+retainlySettings.app_id;var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}})()
- </script>
The Event Tracking Script
You need to add this script in all your web pages where you want to capture an event from your site/app.
This script will track your defined events triggered by your users. These events can be later used inside Retainly to automatically send real-time behavioral campaigns.
- <script>
- TrackEvent('Product Clicked',JSON.stringify({'name':'ABC Item','price':'100'}));
- </script>
Example
The script provided above is an example. 'Product Clicked' is the event name. You can create and name any event depending on your application. The second part of this script is a JSON object which is optional.
Other Examples
<script>TrackEvent('New Bank Account Linked');</script>
<script>TrackEvent('New Stock Purchased');</script>
<script>TrackEvent('New Trade Eqnuiry');</script>
What are the possible fields that can be tracked?
The below list has the complete set of fields that can be used inside window.retianlySettings
Field
|
Remarks
|
name
|
Nickname or nice name of the contact
|
email
|
Email ID of the contact. This is mandatory field
|
signedup_at
|
This is the signed up date of your contact in your application/db
|
plan
|
If the contacts is to be associated with any plan in your app, you can use this field
|
title
|
Title of the contact. E.g., Mr. Ms. etc.,
|
first_name
|
Firstname of the contact
|
last_name
|
Lastname of the contact
|
gender
|
Gender of the contact
|
birthday
|
Birthday of the contact. Pass the values in YYYY-MM-DD format
|
street
|
Address of the contact
|
city
|
City of the contact
|
state
|
State or region of the contact
|
country
|
Country of the contact
|
postal_code
|
Posta code / zip code of the contact
|
country_code
|
Country code of the contact
|
phone
|
Phone / Mobile number of the contact
|
website
|
Website of the contact
|
segments
| You can pass the list/segment name where the contact needs to be grouped in Retainly. e.g., Leads, Customers
|
tags
|
Tags that you want to add to this contact. Use comma separated lists like Beta, Demo
|
company
|
Company of the contact. Will be useful to group them into accounts
|
revenue
|
Revenue that was charged with this contact
|
avatar
|
Avatar URL of the contact
|