Skip to content
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
Close (esc)
const dedicatedPageURL = new URL(window.location.href);
if (dedicatedPageURL?.searchParams?.get('appstle_referral') && _ALConfig?.widget_setting?.widgetType === 'DEDICATED_PAGE' && !window.location.href.includes(_ALConfig?.proxy_path_prefix)) {
window.open(`/${_ALConfig?.proxy_path_prefix}${window.location.search}`, '_self');
}
const dedicatedPageEventListener = (event) => {
if (event?.data && typeof event?.data.indexOf === 'function' && event?.data?.indexOf('refresh_appstle_loyalty_page') !== -1) {
initiateAppstleLoyaltyPage()
console.log("REFRESH PAGE");
}
}
window.addEventListener('message', dedicatedPageEventListener, false);
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://loyalty-admin.appstle.com/app/loyalty-widget.bundle.js?v=1725453867520");
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://loyalty-admin.appstle.com/content/loyalty-widget.css?v=1725453867520";
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() {
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);