Skip to content

Instantly share code, notes, and snippets.

@lennardtastic
Created January 26, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lennardtastic/98d08f071fb3aa8b43089c0957c9c354 to your computer and use it in GitHub Desktop.
Save lennardtastic/98d08f071fb3aa8b43089c0957c9c354 to your computer and use it in GitHub Desktop.
/**The MIT License (MIT)
Copyright (c) 2018 Lennard Schoemaker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
**/
/**
* setEventCallback Function for Usabilla for Websites that integrates with Monetate
* More info can be found on
* https://support.monetate.com/hc/en-us/articles/204308729-setCustomVariables-API-
* https://support.monetate.com/hc/en-us/articles/217014606-API-Methods-and-Code-Examples
*/
window.usabilla_live("setEventCallback", function (usblcategory, usblaction, usbllabel, usblvalue) {
var type = null;
switch (usblaction) {
// This event is raised when a user starts the feedback process, this can be by clicking the feedback button or via a Boost campaign.
case "Feedback:Open":
type = "feedback";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Feedback" },
{ name: "usblAction", value: "Feedback:Open" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// This event is raised when a user has successfully completed the feedback process.
case "Feedback:Success":
type = "feedback";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Feedback" },
{ name: "usblAction", value: "Feedback:Success" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// Event of the Campaign form that shows up
case "Campaign:Open":
type = "campaign";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Campaign" },
{ name: "usblAction", value: "Campaign:Open" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// This event is raised whenever a user actively closes a campaign by either clicking on the close button or the cancel link.
case "Campaign:Close":
type = "campaign";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Campaign" },
{ name: "usblAction", value: "Campaign:Close" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// This event is raised in addition to the Campaign Success event when a Boost campaign is successful.
case "Campaign:Feedback Clicked":
type = "campaign";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Campaign" },
{ name: "usblAction", value: "Campaign:Feedback Clicked" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// This event is raised whenever a campaign is successful:
// - gives feedback while a boost campaign is active
// - clicks the recruit button for a recruit campaign
// - finishes a slide-out or full survey campaign
case "Campaign:Success":
type = "campaign";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Campaign" },
{ name: "usblAction", value: "Campaign:Success" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
// This event is raised whenever a user clicks the submit button for a multi-page campaign (slideout and full survey campaigns).
case "Campaign:Page switch":
type = "campaign";
// Send data to Monetate
window.monetateQ = window.monetateQ || [];
monetateQ.push(["setCustomVariables",
[
{ name: "usblCategory", value: "Campaign" },
{ name: "usblAction", value: "Campaign:Page Switch" },
{ name: "usblActionValue", value: usblvalue }
]
]);
window.monetateQ.push([
"trackData"
]);
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment