(function() {
var widgetConfig = {"tenant_id":"69739933ce1f65fa4eea747c","name":"25% Discout Code","theme_id":"","type":"popup","offer_type":"coupon","headline":"Get 25% Discout Code","subheadline":"We will email you the 25% Discout Code\n","button_text":"I Want Discount!","success_message":"Thanks for subscribing!","coupon_code":null,"lead_magnet_url":null,"target_list_id":"698098029966da1f4ff1be4f","trigger_sequence_id":"698098de00ce383d4466660b","form_fields":{"show_name":true,"require_name":true,"show_phone":false,"require_phone":false},"styling":{"primary_color":"#FF6B9D","background_color":"#ffffff","text_color":null,"border_radius":null,"font_family":null,"headline_font_size":null,"headline_font_weight":null,"subheadline_font_size":null,"button_background_color":null,"button_text_color":null,"button_hover_color":null,"button_border_radius":null,"input_background_color":null,"input_text_color":null,"input_border_color":null,"input_border_radius":null,"background_image_url":"https://images.pexels.com/photos/17114781/pexels-photo-17114781.jpeg?auto=compress&cs=tinysrgb&h=650&w=940","overlay_opacity":null,"max_width":"700px","padding":null,"layout_template":"image_left","column_distribution":50,"scale":85,"box_shadow":null,"text_align":null,"image_position":null},"display_rules":{"delay_seconds":0,"scroll_percentage":60,"exit_intent":true,"inactivity_seconds":60,"position":"center","show_once_per_session":false,"hide_after_submission":true,"cookie_days":null,"show_on_mobile":true,"show_on_desktop":false},"is_active":true,"stats":{"views":70,"submissions":8},"id":"6980995f295de4f92f9d47b3","created_date":"2026-02-02T12:32:31.622000","updated_date":"2026-02-09T17:21:41.782000","created_by_id":"697396f1aca3322013c075ab","created_by":"sorryfatherbiz+1@gmail.com","is_sample":false};
var widgetId = '6980995f295de4f92f9d47b3';
var apiKey = 'a48d1c05-3ce5-4b6f-afd0-c3d6a7cb4d68';
var apiBaseUrl = 'https://leadsno1.com/functions';
var styles = {"primary_color":"#FF6B9D","background_color":"#ffffff","text_color":null,"border_radius":null,"font_family":null,"headline_font_size":null,"headline_font_weight":null,"subheadline_font_size":null,"button_background_color":null,"button_text_color":null,"button_hover_color":null,"button_border_radius":null,"input_background_color":null,"input_text_color":null,"input_border_color":null,"input_border_radius":null,"background_image_url":"https://images.pexels.com/photos/17114781/pexels-photo-17114781.jpeg?auto=compress&cs=tinysrgb&h=650&w=940","overlay_opacity":null,"max_width":"700px","padding":null,"layout_template":"image_left","column_distribution":50,"scale":85,"box_shadow":null,"text_align":null,"image_position":null};
var LeadzWidget = {
createWidgetHTML: function(config, styles) {
var primaryColor = styles.primary_color || '#FF6B9D';
var bgColor = styles.background_color || '#FFFFFF';
var textColor = styles.text_color || '#000000';
var buttonBgColor = styles.button_background_color || primaryColor;
var buttonTextColor = styles.button_text_color || '#FFFFFF';
var buttonBorderRadius = styles.button_border_radius || '6px';
var inputBgColor = styles.input_background_color || '#FFFFFF';
var inputBorderColor = styles.input_border_color || '#ddd';
var inputBorderRadius = styles.input_border_radius || '6px';
var fontFamily = styles.font_family || 'Arial, sans-serif';
var headlineFontSize = styles.headline_font_size || '24px';
var headlineFontWeight = styles.headline_font_weight || 'bold';
var subheadlineFontSize = styles.subheadline_font_size || '14px';
var borderRadius = styles.border_radius || 12;
var padding = styles.padding || '30px';
var maxWidth = styles.max_width || '500px';
var bgImage = styles.background_image_url || '';
var overlayOpacity = styles.overlay_opacity || 0;
var layoutTemplate = styles.layout_template || 'default';
var textAlign = styles.text_align || 'center';
var scale = (styles.scale || 100) / 100;
var columnDistribution = parseInt(styles.column_distribution) || 50;
var imagePosition = styles.image_position || 'center';
// Box shadow mapping
var boxShadowType = styles.box_shadow || 'medium';
var boxShadowMap = {
'none': 'none',
'small': '0 2px 8px rgba(0,0,0,0.08)',
'medium': '0 4px 20px rgba(0,0,0,0.1)',
'large': '0 8px 30px rgba(0,0,0,0.15)',
'xl': '0 12px 40px rgba(0,0,0,0.2)'
};
var boxShadow = boxShadowMap[boxShadowType] || boxShadowMap['medium'];
var formFields = config.form_fields || { show_name: true, require_name: true, show_phone: false, require_phone: false };
var nameFieldHTML = '';
if (formFields.show_name !== false) {
var namePlaceholder = formFields.require_name !== false ? 'Your Name *' : 'Your Name (optional)';
var nameRequired = formFields.require_name !== false ? 'required' : '';
nameFieldHTML = '';
}
var phoneFieldHTML = '';
if (formFields.show_phone === true) {
var phonePlaceholder = formFields.require_phone === true ? 'Phone Number *' : 'Phone Number (optional)';
var phoneRequired = formFields.require_phone === true ? 'required' : '';
phoneFieldHTML = '';
}
var formAlignStyle = textAlign === 'left' ? 'align-items: flex-start;' : (textAlign === 'right' ? 'align-items: flex-end;' : 'align-items: center;');
var formHTML = '
' +
'';
var closeButton = '';
var contentHTML = closeButton + '' + (config.headline || 'Subscribe') + '
' +
'' + (config.subheadline || '') + '
';
// maxWidth is already set from styles, no override needed
var formContentHTML = '' + contentHTML + formHTML + '
';
// Form content for split layouts
var formContentHTMLSplit = '' + contentHTML + formHTML + '
';
// Handle different layout templates
if (bgImage && layoutTemplate === 'image_top') {
return '' +
'
' +
formContentHTML +
'
';
} else if (bgImage && layoutTemplate === 'image_left') {
var imageWidth = columnDistribution + '%';
var formWidth = (100 - columnDistribution) + '%';
var alignItems = imagePosition === 'top' ? 'flex-start' : (imagePosition === 'bottom' ? 'flex-end' : 'center');
return '' +
'
' +
'
' + formContentHTMLSplit + '
' +
'
';
} else if (bgImage && layoutTemplate === 'image_right') {
var imageWidth = columnDistribution + '%';
var formWidth = (100 - columnDistribution) + '%';
var alignItems = imagePosition === 'top' ? 'flex-start' : (imagePosition === 'bottom' ? 'flex-end' : 'center');
return '' +
'
' + formContentHTMLSplit + '
' +
'
' +
'
';
} else if (bgImage && layoutTemplate === 'image_background') {
return '' +
'
' +
'
' + formContentHTML + '
' +
'
';
} else {
// Default layout
var containerStyle = 'background: ' + bgColor + '; padding: ' + padding + '; border-radius: ' + borderRadius + 'px; box-shadow: ' + boxShadow + '; max-width: ' + maxWidth + '; width: 100%; margin: 0 auto; font-family: ' + fontFamily + '; position: relative; transform: scale(' + scale + '); transform-origin: top center;';
return '' + contentHTML + formHTML + '
';
}
},
attachEventListeners: function(widgetId, apiKey, container) {
var form = container.querySelector('#leadz-form');
var messageDiv = container.querySelector('#leadz-message');
var submitBtn = form.querySelector('button[type="submit"]');
var originalBtnText = submitBtn.textContent;
form.addEventListener('submit', function(e) {
e.preventDefault();
submitBtn.disabled = true;
submitBtn.textContent = 'Sending...';
var nameInput = form.querySelector('[name="name"]');
var phoneInput = form.querySelector('[name="phone"]');
var formData = {
name: nameInput ? nameInput.value : '',
email: form.querySelector('[name="email"]').value,
phone: phoneInput ? phoneInput.value : '',
widgetId: widgetId,
sourceUrl: window.location.href
};
var apiUrl = apiBaseUrl + '/captureWidgetLead?apiKey=' + encodeURIComponent(apiKey);
console.log('Submitting to:', apiUrl);
console.log('Form data:', formData);
fetch(apiUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData)
})
.then(function(res) {
console.log('Response status:', res.status);
return res.json();
})
.then(function(data) {
console.log('Response data:', data);
messageDiv.style.display = 'block';
if (data.success) {
messageDiv.style.background = '#d4edda';
messageDiv.style.color = '#155724';
messageDiv.textContent = data.message || 'Thanks for subscribing!';
form.reset();
} else {
messageDiv.style.background = '#f8d7da';
messageDiv.style.color = '#721c24';
messageDiv.textContent = data.error || 'Something went wrong.';
}
submitBtn.disabled = false;
submitBtn.textContent = originalBtnText;
})
.catch(function(err) {
console.error('Fetch error:', err);
messageDiv.style.display = 'block';
messageDiv.style.background = '#f8d7da';
messageDiv.style.color = '#721c24';
messageDiv.textContent = 'Something went wrong. Please try again.';
submitBtn.disabled = false;
submitBtn.textContent = originalBtnText;
});
});
},
createPopupWithTriggers: function(widgetHTML, config, widgetId, apiKey) {
var self = this;
var rules = config.display_rules || {};
var triggered = false;
var lastActivity = Date.now();
// Check device targeting
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
var isCurrentlyMobile = isMobile();
var shouldShowOnDevice = (isCurrentlyMobile && rules.show_on_mobile !== false) || (!isCurrentlyMobile && rules.show_on_desktop !== false);
if (!shouldShowOnDevice) return;
// Check frequency & visibility rules
var cookieKey = 'leadz_widget_' + widgetId;
var sessionKey = 'leadz_session_' + widgetId;
var submittedKey = 'leadz_submitted_' + widgetId;
function getCookie(name) {
var matches = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[]\/+^])/g, '\$1') + '=([^;]*)'));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
function setCookie(name, value, days) {
var expires = '';
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/';
}
// Check if shown this session
if (rules.show_once_per_session !== false) {
if (sessionStorage.getItem(sessionKey)) return;
}
// Check if user has submitted before
if (rules.hide_after_submission !== false) {
if (getCookie(submittedKey)) return;
}
// Check cookie duration
if (rules.cookie_days) {
if (getCookie(cookieKey)) return;
}
function showWidget() {
if (triggered) return;
triggered = true;
// Mark as shown in session
if (rules.show_once_per_session !== false) {
sessionStorage.setItem(sessionKey, 'true');
}
// Set cookie for duration
if (rules.cookie_days) {
setCookie(cookieKey, 'true', rules.cookie_days);
}
var position = rules.position || 'center';
var alignItems = 'center';
var justifyContent = 'center';
// Map position to flex alignment
if (position === 'top-left') {
alignItems = 'flex-start';
justifyContent = 'flex-start';
} else if (position === 'top-center') {
alignItems = 'flex-start';
justifyContent = 'center';
} else if (position === 'top-right') {
alignItems = 'flex-start';
justifyContent = 'flex-end';
} else if (position === 'bottom-left') {
alignItems = 'flex-end';
justifyContent = 'flex-start';
} else if (position === 'bottom-center') {
alignItems = 'flex-end';
justifyContent = 'center';
} else if (position === 'bottom-right') {
alignItems = 'flex-end';
justifyContent = 'flex-end';
}
var overlay = document.createElement('div');
overlay.id = 'leadz-popup-overlay';
overlay.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 9999; display: flex; align-items: ' + alignItems + '; justify-content: ' + justifyContent + '; padding: 20px;';
var popup = document.createElement('div');
popup.innerHTML = widgetHTML;
popup.style.position = 'relative';
overlay.appendChild(popup);
document.body.appendChild(overlay);
self.attachEventListeners(widgetId, apiKey, popup);
// Track form submission
var form = popup.querySelector('#leadz-form');
if (form) {
form.addEventListener('submit', function() {
if (rules.hide_after_submission !== false) {
setCookie(submittedKey, 'true', 365);
}
});
}
var closeBtn = popup.querySelector('.leadz-close-btn');
if (closeBtn) {
closeBtn.addEventListener('click', function() {
document.body.removeChild(overlay);
});
}
}
// Time delay trigger
if (rules.delay_seconds) {
setTimeout(showWidget, rules.delay_seconds * 1000);
}
// Scroll percentage trigger
if (rules.scroll_percentage) {
window.addEventListener('scroll', function() {
var scrolled = (window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100;
if (scrolled >= rules.scroll_percentage) {
showWidget();
}
});
}
// Exit intent trigger
if (rules.exit_intent) {
document.addEventListener('mousemove', function(e) {
if (e.clientY <= 10) {
showWidget();
}
});
}
// Inactivity trigger
if (rules.inactivity_seconds) {
function resetActivity() {
lastActivity = Date.now();
}
document.addEventListener('mousemove', resetActivity);
document.addEventListener('keydown', resetActivity);
document.addEventListener('scroll', resetActivity);
setInterval(function() {
var inactive = (Date.now() - lastActivity) / 1000;
if (inactive >= rules.inactivity_seconds) {
showWidget();
}
}, 1000);
}
// If no triggers set, show immediately
if (!rules.delay_seconds && !rules.scroll_percentage && !rules.exit_intent && !rules.inactivity_seconds) {
showWidget();
}
},
createSlideInWithTriggers: function(widgetHTML, config, widgetId, apiKey) {
var self = this;
var rules = config.display_rules || {};
var triggered = false;
var lastActivity = Date.now();
// Check device targeting
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
var isCurrentlyMobile = isMobile();
var shouldShowOnDevice = (isCurrentlyMobile && rules.show_on_mobile !== false) || (!isCurrentlyMobile && rules.show_on_desktop !== false);
if (!shouldShowOnDevice) return;
// Check frequency & visibility rules
var cookieKey = 'leadz_widget_' + widgetId;
var sessionKey = 'leadz_session_' + widgetId;
var submittedKey = 'leadz_submitted_' + widgetId;
function getCookie(name) {
var matches = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[]\/+^])/g, '\$1') + '=([^;]*)'));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
function setCookie(name, value, days) {
var expires = '';
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + encodeURIComponent(value) + expires + '; path=/';
}
// Check if shown this session
if (rules.show_once_per_session !== false) {
if (sessionStorage.getItem(sessionKey)) return;
}
// Check if user has submitted before
if (rules.hide_after_submission !== false) {
if (getCookie(submittedKey)) return;
}
// Check cookie duration
if (rules.cookie_days) {
if (getCookie(cookieKey)) return;
}
function showWidget() {
if (triggered) return;
triggered = true;
// Mark as shown in session
if (rules.show_once_per_session !== false) {
sessionStorage.setItem(sessionKey, 'true');
}
// Set cookie for duration
if (rules.cookie_days) {
setCookie(cookieKey, 'true', rules.cookie_days);
}
var position = rules.position || 'bottom-right';
var positionStyles = '';
var animationName = 'slideInRight';
var animationKeyframes = '@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }';
// Map position to CSS
if (position === 'top-left') {
positionStyles = 'top: 20px; left: 20px;';
animationName = 'slideInLeft';
animationKeyframes = '@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }';
} else if (position === 'top-center') {
positionStyles = 'top: 20px; left: 50%; transform: translateX(-50%);';
animationName = 'slideInTop';
animationKeyframes = '@keyframes slideInTop { from { transform: translate(-50%, -100%); } to { transform: translate(-50%, 0); } }';
} else if (position === 'top-right') {
positionStyles = 'top: 20px; right: 20px;';
animationName = 'slideInRight';
animationKeyframes = '@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }';
} else if (position === 'bottom-left') {
positionStyles = 'bottom: 20px; left: 20px;';
animationName = 'slideInLeft';
animationKeyframes = '@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }';
} else if (position === 'bottom-center') {
positionStyles = 'bottom: 20px; left: 50%; transform: translateX(-50%);';
animationName = 'slideInBottom';
animationKeyframes = '@keyframes slideInBottom { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }';
} else if (position === 'bottom-right') {
positionStyles = 'bottom: 20px; right: 20px;';
animationName = 'slideInRight';
animationKeyframes = '@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }';
} else if (position === 'center') {
positionStyles = 'top: 50%; left: 50%; transform: translate(-50%, -50%);';
animationName = 'fadeIn';
animationKeyframes = '@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }';
}
var slideIn = document.createElement('div');
slideIn.style.cssText = 'position: fixed; ' + positionStyles + ' z-index: 9999; animation: ' + animationName + ' 0.5s ease-out;';
slideIn.innerHTML = widgetHTML;
var style = document.createElement('style');
style.textContent = animationKeyframes;
document.head.appendChild(style);
document.body.appendChild(slideIn);
self.attachEventListeners(widgetId, apiKey, slideIn);
// Track form submission
var form = slideIn.querySelector('#leadz-form');
if (form) {
form.addEventListener('submit', function() {
if (rules.hide_after_submission !== false) {
setCookie(submittedKey, 'true', 365);
}
});
}
var closeBtn = slideIn.querySelector('.leadz-close-btn');
if (closeBtn) {
closeBtn.addEventListener('click', function() {
document.body.removeChild(slideIn);
});
}
}
// Time delay trigger
if (rules.delay_seconds) {
setTimeout(showWidget, rules.delay_seconds * 1000);
}
// Scroll percentage trigger
if (rules.scroll_percentage) {
window.addEventListener('scroll', function() {
var scrolled = (window.scrollY / (document.documentElement.scrollHeight - window.innerHeight)) * 100;
if (scrolled >= rules.scroll_percentage) {
showWidget();
}
});
}
// Exit intent trigger
if (rules.exit_intent) {
document.addEventListener('mousemove', function(e) {
if (e.clientY <= 10) {
showWidget();
}
});
}
// Inactivity trigger
if (rules.inactivity_seconds) {
function resetActivity() {
lastActivity = Date.now();
}
document.addEventListener('mousemove', resetActivity);
document.addEventListener('keydown', resetActivity);
document.addEventListener('scroll', resetActivity);
setInterval(function() {
var inactive = (Date.now() - lastActivity) / 1000;
if (inactive >= rules.inactivity_seconds) {
showWidget();
}
}, 1000);
}
// If no triggers set, show immediately
if (!rules.delay_seconds && !rules.scroll_percentage && !rules.exit_intent && !rules.inactivity_seconds) {
showWidget();
}
}
};
// Auto-initialize based on widget type
function initWidget() {
var widgetHTML = LeadzWidget.createWidgetHTML(widgetConfig, styles);
if (widgetConfig.type === 'inline') {
// For inline, append to body or use a marker element
var container = document.createElement('div');
container.id = 'leadz-widget-' + widgetId;
container.innerHTML = widgetHTML;
document.body.appendChild(container);
LeadzWidget.attachEventListeners(widgetId, apiKey, container);
} else if (widgetConfig.type === 'popup') {
LeadzWidget.createPopupWithTriggers(widgetHTML, widgetConfig, widgetId, apiKey, styles);
} else if (widgetConfig.type === 'slide_in') {
LeadzWidget.createSlideInWithTriggers(widgetHTML, widgetConfig, widgetId, apiKey, styles);
}
}
// Wait for DOM to be ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initWidget);
} else {
initWidget();
}
})();