Skip to content

Instantly share code, notes, and snippets.

@lennardtastic
Created January 30, 2018 10:42
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/9a132aaaebd47e620ca4ac169bb384d8 to your computer and use it in GitHub Desktop.
Save lennardtastic/9a132aaaebd47e620ca4ac169bb384d8 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.
**/
// Define variables for queue an counter
var _vis_opt_queue = window._vis_opt_queue || [];
var _vis_counter = 0;
// Object for holding Usabilla Custom Variables Data
var usblCustom = window.customObj || {};
// Define function for pushing VWO test data to Usabilla
_vis_opt_queue.push(function () {
try {
if (!_vis_counter) {
var _vis_data = {},
_vis_combination, _vis_id, _vis_l = 0;
for (; _vis_l < _vwo_exp_ids.length; _vis_l++) {
_vis_id = _vwo_exp_ids[_vis_l];
if (_vwo_exp[_vis_id].ready) {
_vis_combination = _vis_opt_readCookie("_vis_opt_exp_" + _vis_id + "_combi");
if (typeof (_vwo_exp[_vis_id].combination_chosen) != "undefined")
_vis_combination = _vwo_exp[_vis_id].combination_chosen;
if (typeof (_vwo_exp[_vis_id].comb_n[_vis_combination]) != "undefined") {
_vis_data["VWO-Test-ID-" + _vis_id] = _vwo_exp[_vis_id].comb_n[_vis_combination];
_vis_counter++;
}
}
}
// Use the _vis_data object created above to fetch the data,
// key of the object is the Test ID and the value is Variation Name
if (_vis_counter) {
// Console Log for debugging
// console.log(_vis_data);
var usbl_vwo_experiment_id = window._vis_opt_experiment_id;
var usbl_vwo_experiment_name = window._vwo_exp[usbl_vwo_experiment_id].name;
var usbl_vwo_experiment_type = window._vwo_exp[usbl_vwo_experiment_id].type;
var usbl_vwo_experiment_status = window._vwo_exp[usbl_vwo_experiment_id].status;
var usbl_vwo_experiment_regex = window._vwo_exp[usbl_vwo_experiment_id].urlRegex;
var usbl_vwo_experiment_version = window._vwo_exp[usbl_vwo_experiment_id].version;
var usbl_vwo_experiment_variation = window._vwo_exp[usbl_vwo_experiment_id].comb_n[usbl_vwo_experiment_version];
// Set Custom Variables Usabilla using VWO data
usblCustom["vwo_experiment_id"] = usbl_vwo_experiment_id;
usblCustom["vwo_experiment_name"] = usbl_vwo_experiment_name;
usblCustom["vwo_experiment_type"] = usbl_vwo_experiment_type;
usblCustom["vwo_experiment_status"] = usbl_vwo_experiment_status;
usblCustom["vwo_experiment_regex"] = usbl_vwo_experiment_regex;
usblCustom["vwo_experiment_version"] = usbl_vwo_experiment_version;
usblCustom["vwo_experiment_variation"] = usbl_vwo_experiment_variation;
// Init Custom Variables
window.usabilla_live("data", {
"custom": usblCustom
});
}
}
} catch (err) {}
});
// Init Custom Variables
window.usabilla_live("data", {
"custom": usblCustom
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment