@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 4.57 kB
JavaScript
import a from"../data";import u from"../tools/settings";import s from"../tools/track-event";import k from"../utils/is-debug";const d="G-78CKLYWFJK";window.dataLayer=window.dataLayer||[];export default function i(...e){window.dataLayer.push(arguments)}export var GaEventActions;(function(e){e.Load="Load floor plan",e.ViewBooth="View booth",e.ViewExhibitor="View exhibitor",e.ViewCategory="View category",e.Search="Search",e.ClickCustomButton="Click custom button",e.ViewVideo="View video",e.ViewGallery="View gallery",e.ClickPhone="Click phone",e.ClickEmail="Click email",e.ClickWebsite="Click website",e.ClickFacebook="Click Facebook",e.ClickInstagaram="Click Instagram",e.ClickLinkedin="Click Linkedin",e.ClickTwitter="Click Twitter",e.ClickGooglePlus="Click Google Plus",e.ClickXing="Click Xing",e.ClickYoutube="Click Youtube",e.ClickDirections="Click Directions",e.Rendered="Floor plan rendered"})(GaEventActions||(GaEventActions={}));export async function checkUserIsGDPR(){try{const e=fetch("https://consent.expofp.com/api/verify-ip/is-in-gdpr"),t=new Promise(r=>{setTimeout(()=>{r(null)},5e3)}),o=await Promise.race([e,t]);return o instanceof Response&&o.ok?(await o.json()).result:null}catch(e){return console.error(e),null}}export function hasUserConsent(e){if(e===!1||e===!0)return e?"granted":"denied";const t=document.cookie.split("; ").find(o=>o.startsWith("cookie_consent="));if(t)return t==="cookie_consent=true"?"granted":"denied"}export function setCookieConsent(e){const o=k?"localhost":".expofp.com";document.cookie=`cookie_consent=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${o}`,document.cookie="cookie_consent=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/",document.cookie=e?`cookie_consent=${e}; max-age=2592000; domain=${o}; path=/`:`cookie_consent=${e}; max-age=2592000; path=/`}function p(){const e=document.cookie.split(";"),t=k?"localhost":".expofp.com";for(let o=0;o<e.length;o++){const r=e[o],l=r.indexOf("="),g=l>-1?r.substr(0,l).trim():r.trim();g.startsWith("_ga")&&(document.cookie=`${g}=;expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${t}`)}}export function setConsentSettings(e){let t=hasUserConsent(e);t&&(t==="denied"?(p(),a.gtag&&(window[`ga-disable-${a.gtag}`]=!0),window[`ga-disable-${d}`]=!0):(a.gtag&&(window[`ga-disable-${a.gtag}`]=!1),window[`ga-disable-${d}`]=!1),i("consent","update",{analytics_storage:t,ad_personalization:t}))}export function sendEventToGa(e,t,o){switch(e){case GaEventActions.ViewBooth:{i("event","select_content",{content_type:e,content_id:t}),s("booview",t);break}case GaEventActions.ViewCategory:{i("event","select_content",{content_type:e,content_id:t}),s("catview",t);break}case GaEventActions.ViewExhibitor:case GaEventActions.ViewGallery:case GaEventActions.ViewVideo:i("event","select_content",{content_type:e,content_id:t});break;case GaEventActions.Search:i("event","search",{search_term:t}),s("search",t);break;case GaEventActions.ClickCustomButton:case GaEventActions.ClickPhone:case GaEventActions.ClickEmail:case GaEventActions.ClickWebsite:case GaEventActions.ClickFacebook:case GaEventActions.ClickInstagaram:case GaEventActions.ClickLinkedin:case GaEventActions.ClickTwitter:case GaEventActions.ClickGooglePlus:case GaEventActions.ClickXing:case GaEventActions.ClickYoutube:i("event","share",{content_type:e,content_id:t}),s("share",t);break;case GaEventActions.ClickDirections:i("event","route",{content_type:e,content_id:t}),s("route",t);break;default:i("event",e,{content_type:o,content_id:t})}}let n,c;if(!n){n=document.createElement("script"),n.type="text/javascript",n.async=!0,n.src=`https://www.googletagmanager.com/gtag/js?id=${d}`;const e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(n,e),i("js",new Date)}if(a.gtag&&!c){c=document.createElement("script"),c.type="text/javascript",c.async=!0,c.src=`https://www.googletagmanager.com/gtag/js?id=${a.gtag}`;const e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(c,e),i("config",a.gtag,{fp_key:u.EXPO})}i("config",d,{fp_key:u.EXPO}),window.gtag=i,i("consent","default",{ad_storage:"denied",analytics_storage:"denied",region:["BE","BG","CZ","DK","DE","EE","IE","EL","ES","FR","HR","IT","CY","LV","LT","LU","HU","MT","NL","AT","PL","PT","RO","SI","SK","FI","SE","UK","IS","NO","LI","CH","MK","AL","RS","TR"],functionality_storage:"denied",personalization_storage:"denied",security_storage:"denied",ad_personalization:"denied"});export function destroyGtag(){n&&n.parentNode&&(n.parentNode.removeChild(n),n=null),c&&c.parentNode&&(c.parentNode.removeChild(c),c=null)}