var personalizationSnippet = function() {
var defaultUrl = 'https://img.hyperise.io/i/{{image_hash}}.png';
var serviceUrl = 'https://app.hyperise.io/snippets/hp/fetch-data';
var settingsUrl = 'https://app.hyperise.io/snippets/hp/fetch-settings';
var availableParams = JSON.parse('["business_name","business_phone","business_address","website","fb_id","category","title","first_name","last_name","gender","job_title","phone","home_phone","email","employees_range","revenue","custom_text_1","custom_text_2","custom_text_3","custom_text_4","custom_text_5","logo","profile_image","profile_url","custom_image_1","custom_image_2","custom_image_3","country","state","city","street","street2","zip","lat","long","appstore_link","qr_url","qr_text"]');
availableParams.push('utm_hyperef');
availableParams.push('utm_campaign');
availableParams.push('utm_source');
availableParams.push('utm_medium');
availableParams.push('utm_term');
availableParams.push('utm_content');
var availableSegmentParams = ["utm_campaign", "utm_source", "utm_medium", "utm_term", "utm_content"];
var settingsPrepared = false;
var settings = {};
var accountHash = 'CtNkxyNw1';
var paramId = 0;
var originalId = 0;
var dynamicData = {};
var dynamicDataApplied = {};
var appliedChanges = [];
var imageIdUsed = false;
var self = null;
var novUpdated = false;
var formEventAttempt = 0;
callAjax = function(url, data, callback) {
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
callback(xmlhttp.response);
}
}
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify(data));
}
fbPixelBlock = function() {
var pixelId = settings.pixelId || false;
if (!pixelId) {
return;
}
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', pixelId);
fbq('track', 'PageView');
fbq('track', 'ViewContent', {
content_ids: [originalId],
content_type: 'product'
});
document.body.insertAdjacentHTML('beforeend', '');
}
function getParams (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] && pair[1] && (availableParams.indexOf(pair[0]) >= 0 || pair[1].substring(0, 8) == 'https://' || pair[1].substring(0, 7) == 'http://')) {
params[pair[0]] = url.searchParams.get(pair[0]);
}
}
return params;
};
function getSegmentParams (url) {
var params = {};
var parser = document.createElement('a');
parser.href = url;
var query = parser.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (pair[0] && pair[1] && availableSegmentParams.indexOf(pair[0]) >= 0) {
params[pair[0]] = url.searchParams.get(pair[0]);
}
}
params.referrer = document.referrer;
var nov = getCookie('whr_nov');
params.number_of_visits = nov;
return params;
};
function setCookie(name,value,days,path) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=" + (path ? path : '/') + "; SameSite=None; Secure";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name+'=; Max-Age=-99999999;';
}
function revertContextItem(item) {
if (item.type == 'Image') {
if (item.old_content) {
jQuery(item.selector).html(item.old_content);
} else if (jQuery(item.selector).attr(getImageSourceAttrName(item.selector)) == item.new_src) {
jQuery(item.selector).attr(getImageSourceAttrName(item.selector), item.old_src);
}
if (item.attributes) {
for (let i = 0; i < item.attributes.length; i++) {
jQuery(item.selector).attr(item.attributes[i].name, item.attributes[i].old);
}
}
} else if (item.type == 'Text') {
if (jQuery(item.selector).html() == item.new_content) {
jQuery(item.selector).html(item.old_content);
}
} else if (item.type == 'Input') {
if (jQuery(item.selector).val() == item.new_content) {
jQuery(item.selector).val(item.old_content);
}
} else if (item.type == 'Video') {
if (item.new_selector) {
jQuery(item.new_selector).replaceWith(item.old_image_html);
} else {
jQuery(item.selector).html(item.old_content);
}
}
}
function getImageSourceAttrName(selector) {
var objects = jQuery(selector);
if (objects.length == 0) {
return 'src';
}
var nodeName = objects[0].nodeName.toLowerCase();
if (nodeName == 'source') {
return 'srcset';
}
if (objects.length) {
if (jQuery(selector).attr('srcset')) {
return 'srcset'
} else if (jQuery(selector).attr('src')) {
return 'src';
}
}
return 'src';
}
function applyContextItem(item, serviceData) {
if (item.type == 'Image') {
if (serviceData.image_urls[item.image_template_id]) {
if (jQuery(item.selector).length > 0) {
if (item.old_content) {
appliedChanges.push({
type: item.type,
selector: item.selector,
old_content: jQuery(item.selector).html(),
new_src: serviceData.image_urls[item.image_template_id],
});
var html = '';
jQuery(item.selector).html(html);
} else {
appliedChanges.push({
type: item.type,
selector: item.selector,
old_src: item.old_image_url,
new_src: serviceData.image_urls[item.image_template_id]
});
var changedAttributes = [];
var srcAttrName = getImageSourceAttrName(item.selector);
jQuery(item.selector).attr(srcAttrName, serviceData.image_urls[item.image_template_id]);
if (jQuery(item.selector).attr('data-' + srcAttrName)) {
jQuery(item.selector).removeAttr('data-' + srcAttrName);
}
if (srcAttrName == 'src') {
let imgAttributes = jQuery(item.selector)[0].attributes;
for (let attrKey in imgAttributes) {
let attrName = imgAttributes[attrKey].name;
let attrValue = imgAttributes[attrKey].value;
if (typeof attrName == 'string' && attrName.indexOf('srcset') >= 0 && attrValue.length > 0) {
let srcsetParts = attrValue.split(',');
if (srcsetParts.length > 0) {
let newSet = [];
for (let ix = 0; ix < srcsetParts.length; ix++) {
let part = srcsetParts[ix].split(' ');
if (part.length > 1) {
newSet.push(serviceData.image_urls[item.image_template_id] + ' ' + part[part.length - 1]);
}
}
changedAttributes.push({
'name': attrName,
'old': jQuery(item.selector).attr(attrName)
})
jQuery(item.selector).attr(attrName, newSet.join(', '));
}
} else if (typeof attrName == 'string' && attrName.indexOf('-src') >= 0 && attrValue.length > 0) {
changedAttributes.push({
'name': attrName,
'old': jQuery(item.selector).attr(attrName)
})
jQuery(item.selector).attr(attrName, serviceData.image_urls[item.image_template_id]);
}
}
}
if (changedAttributes.length) {
appliedChanges[appliedChanges.length - 1].attributes = changedAttributes;
}
setTimeout(function() {jQuery(item.selector).attr(getImageSourceAttrName(item.selector), serviceData.image_urls[item.image_template_id]);}, 1000);
}
} else {
item.attempt = item.attempt ? item.attempt + 1 : 1;
if (item.attempt <= 5) {
setTimeout(applyContextItem, 1000 * item.attempt, item, serviceData);
}
}
if (settings.hasOwnProperty('imageId')
&& settings.imageId
&& serviceData.image_hashes[item.image_template_id] == settings.imageTemplate) {
appliedChanges.push({
type: item.type,
selector: '#' + settings.imageId,
old_src: jQuery('#' + settings.imageId).attr(getImageSourceAttrName('#' + settings.imageId)),
new_src: serviceData.image_urls[item.image_template_id]
});
jQuery('#' + settings.imageId).attr(getImageSourceAttrName('#' + settings.imageId), serviceData.image_urls[item.image_template_id]);
}
}
} else if (item.type == 'Video' && item.old_image_url) {
if (serviceData.video_urls[item.video_template_id]) {
if (jQuery(item.selector).length > 0) {
appliedChanges.push({
type: item.type,
selector: item.selector,
old_src: item.old_image_url,
new_src: serviceData.video_urls[item.video_template_id],
new_selector: '#hr_video_' + item.video_template_id,
old_image_html: jQuery('