Web SDK
Launch CustomerGlu games, challenges, rewards and nudges on web applications/websites within minutes...
Last updated
<script type="text/javascript">
window["gluConfig"] = {
writeKey: "{{WRITE_KEY}}", //provided by CustomerGlu
userIdentification: {
userId: "{{USER_ID}}",
anonymousId: "{{ANONYMOUS_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>glu.register(writeKey: string, userIdentification: IUserIdentification, userAttributes: IUserAttributes);interface IUserIdentification {
userId?: string;
anonymousId?: string;
}interface IUserAttributes {
gluAttributes?: {
userName?: string;
appVersion?: string;
deviceType?: string;
deviceName?: string;
deviceId?: string;
firebaseToken?: string;
};
customAttributes?: {
[key: string]: string | number;
};
}glu.open(container: IContainer, content: IContent): Promise<string>/* 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;
}
}`
}/* 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;
}`
}/* 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;
}
}`
}/* 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;
}
}`
}/* 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;
}`
}/* interface */
interface IWallet {
typeId: "WALLET";
}
/* example */
const content: IWallet = {
typeId: string
}/* interface */
interface ICampaign {
typeId: "CAMPAIGN";
conditions: {
campaignId?: string[];
type?: "referral" | "gamechallenge" | "streak" | "multistep" | "spinthewheel" | "scratchcard" | "slotmachine" | "giftbox" | "tossthecoin" | "memorygame" | "catchinggame" | "quiz" | "direct" [];
status?: "pristine" | "in-progress" | "completed" [];
};
}
/* example #1: select a single campaign */
const content: ICampaign = {
typeId: "CAMPAIGN",
conditions: {
campaignId: ["asd283mkla-3890njakd-jkandsk3-kjadnjk3"]
}
}
/* example #2: select a scratch card if present else a spin the wheel campaign if present */
const content: ICampaign = {
typeId: "CAMPAIGN",
conditions: {
type: ["scratchcard", "spinthewheel"]
}
}/* interface */
interface IStaticImage {
typeId: "STATIC";
src: string;
action: IAction; // <- on click action
}
/* example #1: on click redirect */
const content: IStaticImage = {
typeId: "STATIC",
src: "https://uploads-ssl.webflow.com/60ae16f0e20bce50d40c3c7e/61efce5c2ab738e60fd0856f_Group%2027.png",
action: {
type: "REDIRECT",
data: {
url: "https://website.com/rewards"
}
}
}
/* example #2: on click open wallet in a pop up */
const content: IStaticImage = {
typeId: "STATIC",
src: "https://uploads-ssl.webflow.com/60ae16f0e20bce50d40c3c7e/61efce5c2ab738e60fd0856f_Group%2027.png",
action: {
type: "TOGGLE_FRAME_CONTENT";
id: string;
container: {
typeId: "POP_UP",
css: `
.__glu_container {
border-radius: 10px;
background-color: #000;
cursor: pointer;
}
`},
content: {
typeId: "WALLET"
}
}
}
/* example #3: on click open a campaign in a bottom sheet */
const content: IStaticImage = {
typeId: "STATIC",
src: "https://uploads-ssl.webflow.com/60ae16f0e20bce50d40c3c7e/61efce5c2ab738e60fd0856f_Group%2027.png",
action: {
type: "TOGGLE_FRAME_CONTENT";
id: string;
container: {
typeId: "BOTTOM_SHEET",
css: `
.__glu_container {
border-radius: 10px;
background-color: #000;
cursor: pointer;
}
`},
content: {
typeId: "CAMPAIGN",
conditions: {
campaignId: ["asd283mkla-3890njakd-jkandsk3-kjadnjk3"]
}
}
}
}glu.close(id: string);glu.getCampaignDetails(filter: IFilter, config: IConfig): Promise<ICampaignDetailsResult>/* filter interface */
interface ICampaingDetailsFilter {
campaignId?: (string | boolean | number)[] | string;
[key: string]: (string | boolean | number)[] | string;
}
/* config interface */
interface ICampaingDetailsConfig {
includeRewards: boolean;
}
/* RESULT interface */
interface ICampaignDetailsResult {
details: {
campaignId: string;
status: "pristine" | "completed";
type: string;
url: string;
banner?: any;
};
rewards?: {
game_name?:
| "spinthewheel"
| "memorygame"
| "scratchcard"
| "slotmachine"
| "quiz"
| "direct"
| "giftbox"
| "not_available"
| "swipeui"
| "tossthecoin"
| "unitygame"
| "rollthedice";
state?: "pristine" | "complete" | "expired" | "not_available";
campaign_id?: string;
reward_user_id?: string;
user_id?: string;
status?: string;
selected_slot_index?: number | "not_available";
reward_name?: string;
reward_type?: string;
code?: string;
reward_amount?: string | number;
details?: { [key: string]: string } | "not_available";
}[];
}
/* example */
glu
.getCampaignDetails(
{ campaignId: "f8cca67-596e-4b28-a173-8a018cdb2cf8" },
{ includeRewards: true }
)
.then((res) => {
document.querySelector("#app").textContent = JSON.stringify(res);
}).catch(err => console.log(err));glu.addAnalyticsListener(listener: (analyticsEvent: any) => void)