Web SDK
Launch CustomerGlu games, challenges, rewards and nudges on web applications/websites within minutes...
Paste the given snippet in your website’s HTML file just before closing the body (
</body>
) tag.<script type="text/javascript">
window["gluConfig"] = {
writeKey: "{{WRITE_KEY}}", //provided by CustomerGlu
userIdentification: {
userId: "{{USER_ID}}",
anonymousId: "{{ANNONYMOUS_ID}}",
userToken: "TOKEN" //using this will make writeKey optional
},
userAttributes: {
gluAttributes: {}, //add CG reserved user properties here (key-value pair)
customAttributes: {} //add all your custom user properties here (key-value pair)
},
onLoadError: function () { //error handling function if SDK fails to load
console.log("error");
}
};
</script>
<script type="text/javascript">
(()=>{"use strict";!function(){const e=window.gluConfig||{},t=[],o={open:{returnPromise:!0,callMethod:"open"},close:{returnPromise:!1,callMethod:"close"},register:{returnPromise:!1,callMethod:"register"},listenToAnalytics:{returnPromise:!1,callMethod:"listenToAnalytics"},getCampaignDetails:{returnPromise:!0,callMethod:"getCampaignDetails"}},r=["open","close","register","listenToAnalytics","getCampaignDetails"],n={};for(let e=0;e<r.length;e++)n[r[e]]=function(){const n=o[r[e]],s=Array.prototype.slice.call(arguments);if(n.returnPromise)return new Promise(((e,o)=>{t.push({callMethod:n.callMethod,arguments:s.concat({resolve:e,reject:o}),isPromise:!0})}));t.push({callMethod:n.callMethod,arguments:s})};let s=document.createElement("script");s.type="text/javascript",s.async=!0,s.src="https://assets.customerglu.com/scripts/sdk/v4.6/sdk.js",s.onload=function(){const o=new window.CustomerGlu(e.writeKey,e.userIdentification,e.userAttributes);for(let e=0;e<t.length;e++)o[t[e].callMethod](...t[e].arguments);window.glu=o},s.onerror=function(){if(t&&t.length){for(let e=0;e<t.length;e++)t[e].isPromise&&t[e].arguments[t[e].arguments.length-1]("GLU_SDK_LOAD_ERROR");e.onLoadError&&e.onLoadError()}},document.getElementsByTagName("body")[0].appendChild(s),window.glu=n}()})();
</script>
Replace the variables with correct values.
⚠
You are now ready to load CustomerGlu UI on your website. You can now use:
- The Nudges & Entry points section on the dashboard to automate the layout and conditions to open CG campaigns.
- The Below-mentioned SDK Functionality to programmatically load campaigns.
On pasting the above script, a global instance
glu
will be available in the window.The
glu
instance supports the given methods:Use the given method to register a user with CustomerGlu:
glu.register(writeKey: string, userIdentification: IUserIdentification, userAttributes: IUserAttributes);
⚠
writeKey
is a string that will be provided by CustomerGlu.UserIdentification
follows the given structure:interface IUserIdentification {
userId?: string;
anonymousId?: string;
}
- If the user is not logged in the platform,
userId
can be null, andanonymousId
can be passed (an anonympusId will be auto-assigned if not passed explicitly). User progress/state of the campaigns will be linked to the anonymousId - After the user logs in, the same
anonymousId
and theuserId
can be passed. And progress linked toanonymousId
will be linked with theuserId
. If user is already logged in, userId can be passed directly.
At least one function call with both - anonymousId and userId is required to map the anonymousId to the userId after the user logs in.
⚠
UserAttributes
are used for segmentation. They follow the given structure:
interface IUserAttributes {
gluAttributes?: {
userName?: string;
appVersion?: string;
deviceType?: string;
deviceName?: string;
deviceId?: string;
firebaseToken?: string;
};
customAttributes?: {
[key: string]: string | number;
};
}
customAttributes
can hold any extra key-value pair that might be used for user segmentation/other purposes. Example: {"location":"Mumbai""}
The given function can be used to render CustomerGlu UI fragments on the screen:
glu.open(container: IContainer, content: IContent): Promise<string>
container
holds the container details. i.e. If the UI is a bottom sheet, pop up or be embedded etc.- The styling of the container can be customised using the
css
property present in each container type. The container elements are targeted using special class names. - Different containers can have same class names for styling, but the styles gets scoped to only the targeted container.
- Media queries and your custom CSS variables can also be used inside the string.
All supported
container
types are listed down below:Popup
Bottom Sheet
Floating Icon Button
Chat Box
Embed

/* interface */
interface IPopUp {
typeId: "POP_UP";
css: string;
}
/* example */
const container: IPopUp = {
typeId: "POP_UP",
css: `
.__glu_container {
border-radius: 10px;
background-color: #000;
cursor: pointer;
}
.__glu_backdrop {
background-color: #000;
opacity: 0.5;
}
@media screen and (max-width: 700px) {
.__glu_container {
height: 400px;
width: 40p0x;
}
}`
}
.png?alt=media&token=8fa0d265-c25b-4ef7-b5d6-2f39a8a6e829)
/* interface */
interface IBottomSheet {
typeId: "BOTTOM_SHEET";
css: string;
height: string; // <- in px or %
}
/* example */
const container: IBottomSheet = {
typeId: "BOTTOM_SHEET",
height: "60%",
css: `
.__glu_container {
border-top-left-radius: 20px;
border-top-right-radius: 5px;
background-color: #fff;
}
.__glu_backdrop {
background-color: #000;
opacity: 0.5;
}`
}
.png?alt=media&token=222f4558-4ba5-4bd9-b75f-e37fa522c44c)
/* interface */
interface IIconButton {
typeId: "ICON_BUTTON";
css: string;
}
/* example */
const container: IIconButton = {
typeId: "ICON_BUTTON",
css: `
.__glu_container {
border-radius: 50%;
background-color: #000;
cursor: pointer;
}
@media screen and (max-width: 450px) {
.__glu_container {
height: 40px;
width: 40px;
}
}`
}
.png?alt=media&token=d8695260-6ae2-4689-ac37-4db39405918f)
/* interface */
interface IChatBox {
typeId: "CHAT_BOX";
css: string;
}
/* example */
const container: IChatBox = {
typeId: "CHAT_BOX",
css: `
.__glu_container {
border-radius: 12px;
background-color: #000;
cursor: pointer;
}
@media screen and (max-width: 450px) {
.__glu_container {
height: 100vh;
width: 100vw;
}
}`
}
.png?alt=media&token=de54ab48-e5f8-4cb2-b58a-e0ef42273edb)
/* interface */
interface IEmbedded {
typeId: "EMBEDDED";
css: string;
elementHookId: string; // <- HTML elelemt selector (eg: .class, #id, main, body)
}
/* example */
const embedded: IEmbedded = {
typeId: "EMBEDDED",
elementHookId: "#app",
css: `
.__glu_container {
width: 500px;
margin: 0 auto;
height: 1000px;
overflow: scroll;
}`
}
⚠
elementHookId
should be a valid html selector or element on the page. The glu container will be appended inside the that element
All supported
content
types are listed down below:Wallet
Campaign
Static Image
.png?alt=media&token=dcf8ca26-a0ce-4353-a05a-551377c91d9c)
Code
/* interface */
interface IWallet {
typeId: "WALLET";
}
/* example */
const content: IWallet = {
typeId: string
}