Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Clark ogii

View GitHub Profile
@ogii
ogii / elementCheck.js
Last active Feb 5, 2019
Wait until an element exists on the page and then fire some code
View elementCheck.js
function waitForElement() {
if (!document.querySelector("/* put element selector here */")) {
window.requestAnimationFrame(waitForElement);
} else {
/* put code to fire after element exists here */
}
};
@ogii
ogii / timeOnPageTracker.js
Created Feb 5, 2019
Track time spent on page and fire VWO goals
View timeOnPageTracker.js
setInterval(function(){
if(parseInt(timeSpentOnSite/1000) >= 5){
window._vis_opt_queue = window._vis_opt_queue || [];
window._vis_opt_queue.push(function() {_vis_opt_goal_conversion(212);});
}
if(parseInt(timeSpentOnSite/1000) >= 10){
window._vis_opt_queue = window._vis_opt_queue || [];
window._vis_opt_queue.push(function() {_vis_opt_goal_conversion(213);});
}
if(parseInt(timeSpentOnSite/1000) >= 20){
@ogii
ogii / scrollEventTracker.js
Created Feb 5, 2019
Tracking scroll goals in VWO
View scrollEventTracker.js
var scrollPos = window.innerHeight;
window.addEventListener('scroll', function(e) {
var pos = window.scrollY + window.innerHeight;
window._vis_opt_queue = window._vis_opt_queue || [];
if (scrollPos < pos) {
// down
if ((document.querySelector('div.top').getBoundingClientRect().top + window.scrollY) < pos) {
window._vis_opt_queue.push(function() {
_vis_opt_goal_conversion(200);
});
View gist:74c6161d887a5f3cee7fa9c1185c65df
//
var arrayLocation = [];
var arrayArea = [];
var arrayTheme = [];
$('#g-body').prepend('<select style="display: block;" id="select1"></select><select style="display: block;" id="select2"></select><select style="display: block;" id="select3"></select>');
$('div#plase ul.m-tileLink:eq(0) > li').each(function(i,e){
arrayLocation.push([vwo_$(this).children('a').html(), vwo_$(this).children('a').attr('href')]);
});
$('div#plase ul.m-tileLink:eq(1) > li').each(function(i,e){
arrayArea.push([vwo_$(this).children('a').html(), vwo_$(this).children('a').attr('href')]);
@ogii
ogii / imageselect-vwo.js
Created Feb 1, 2018
Loading images into array + showing based on selection in VWO
View imageselect-vwo.js
vwo_$('a#severModalBTN, a#selectModalBTN').on('click', function(element) {
step2(vwo_$('#select-server input[type*="radio"]').filter(':checked').attr('value'));
});
function step2(input) {
switch (input) {
case '27':
isSlimOrNot = true;
step3(vwo_$('div.normal').find(':checked').attr('value'));
break;