Skip to content
icon-search
Close (esc)
let appstleReferralUrl = new URL(window.location.href);
let searchParams = new URLSearchParams(appstleReferralUrl.search);
let referralPage = searchParams.get('appstle_referral');
if (referralPage) {
if (_ALConfig?.widget_setting?.widgetType === 'DEDICATED_PAGE') {
if (!(window?.location?.href?.includes(_ALConfig?.proxy_path_prefix))) {
window.open(`/${_ALConfig?.proxy_path_prefix + window.location.search}`, '_self');
}
} else {
let redirectURL = _ALConfig?.widget_setting?.referralRedirectUrl;
if (redirectURL) {
redirectURL = redirectURL + window?.location?.search;
if (!(window?.location?.pathname?.includes(_ALConfig?.widget_setting?.referralRedirectUrl))) {
window.open(redirectURL, '_self');
}
}
}
}
function initiateAppstleLoyaltyPage() {
if (document.querySelector('#appstleLoyaltyPage')) {
const appstleLoyaltyPageElement = document.getElementById('appstleLoyaltyPage');
while (appstleLoyaltyPageElement.firstChild) {
appstleLoyaltyPageElement.firstChild.remove();
}
var s = document.createElement('script');
s.setAttribute('src', "https://cdn.shopify.com/s/files/1/0565/6539/9704/t/5/assets/appstle_loyalty.js?v=1693555617");
s.setAttribute('defer', 'defer');
document.body.appendChild(s);
var head = document.head;
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = "https://cdn.shopify.com/s/files/1/0565/6539/9704/t/5/assets/appstle_loyalty.css?v=1693555618";
head.appendChild(link);
} else {
setTimeout(() => {
initiateAppstleLoyaltyPage();
}, 2000);
}
}
const checkDedicatedPageForRestrictions = () => {
const { widget_setting, customerTags, customerLoyalty } = _ALConfig || {};
const { allowedCustomersTag, restrictedCustomersTag } = widget_setting || {};
const { customerStatus } = customerLoyalty || {};
if (customerStatus === 'EXCLUDED') {
return false;
}
if (allowedCustomersTag?.length) {
const allowedTags = allowedCustomersTag.split(',');
if (!allowedTags.some(tag => customerTags?.includes(tag))) {
return false;
}
}
if (restrictedCustomersTag?.length) {
const restrictedTags = restrictedCustomersTag.split(',');
if (restrictedTags.some(tag => customerTags?.includes(tag))) {
return false;
}
}
return true;
};
if (_ALConfig?.widget_setting?.showWidget === true && checkDedicatedPageForRestrictions()) {
initiateAppstleLoyaltyPage();
}
(async function visitShop() {
if (_ALConfig?.widget_setting?.showWidget === true) {
const isAvailableVisitShop = _ALConfig?.pointEarnRules?.length > 0 && _ALConfig?.pointEarnRules?.find((rule) => rule?.type === 'VISIT_SHOP' && rule?.status === 'ACTIVE');
if (!sessionStorage.getItem('syncVisitStore') && ((_ALConfig?.customerId && isAvailableVisitShop && isAvailableVisitShop?.id) || (_ALConfig?.referralEnabled && _ALConfig?.referralLoyalty?.referralType === 'VISIT_SHOP'))) {
try {
const response = await fetch(`/apps/loyalty/cp/api/customer-visit-store`, {method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ customerId: _ALConfig?.customerId })});
if(response?.ok){
sessionStorage.setItem('syncVisitStore', 'true');
}
} catch (error) {
console.error('Error:', error);
}
}
}
})();
const loyaltyCustomStyles = ``
document.querySelector('body').insertAdjacentHTML('beforeend', loyaltyCustomStyles);