class DistilleryGeofence{constructor(){this.distilleryLocation={lat:41.566345,lng:-83.653526};this.radius=4828.03;this.isInside=false;this.notificationSent=false;this.visitorData=this.loadVisitorData();this.reminderSent=false;this.consentGiven=this.checkConsentStatus();this.initWithConsent()}checkConsentStatus(){const e=localStorage.getItem("flatrockGeofenceConsent");return e==="true"}saveConsentStatus(e){localStorage.setItem("flatrockGeofenceConsent",e.toString());this.consentGiven=e}initWithConsent(){if(this.consentGiven){this.init();return}this.showPrivacyNotice()}showPrivacyNotice(){const e=document.createElement("div");e.style.position="fixed";e.style.left="0";e.style.top="0";e.style.width="100%";e.style.height="100%";e.style.backgroundColor="rgba(0,0,0,0.7)";e.style.zIndex="10000";e.style.display="flex";e.style.justifyContent="center";e.style.alignItems="center";const t=document.createElement("div");t.style.backgroundColor="#fff";t.style.padding="30px";t.style.borderRadius="8px";t.style.maxWidth="500px";t.style.boxShadow="0 4px 8px rgba(0,0,0,0.2)";const i=document.createElement("div");i.style.textAlign="center";i.style.marginBottom="20px";i.innerHTML='Flatrock Distilling Company';t.appendChild(i);const s=document.createElement("h2");s.textContent="Location-Based Notifications";s.style.fontSize="20px";s.style.marginBottom="15px";t.appendChild(s);const n=document.createElement("p");n.innerHTML=` We'd like to send you notifications when you're within 3 miles of our distillery.

How it works:
• We'll check your location only when our website is open in your browser
• You'll receive notifications about special events, featured menu items, and promotions
• Your location data is only stored locally on your device
• We never share your location data with third parties

You can disable this feature at any time by clearing your browser data or by clicking "Disable" in our footer. `;n.style.lineHeight="1.5";n.style.marginBottom="25px";t.appendChild(n);const a=document.createElement("div");a.style.display="flex";a.style.justifyContent="space-between";const o=document.createElement("button");o.textContent="No Thanks";o.style.padding="10px 20px";o.style.border="1px solid #ccc";o.style.borderRadius="4px";o.style.backgroundColor="#f2f2f2";o.style.cursor="pointer";const r=document.createElement("button");r.textContent="Enable Notifications";r.style.padding="10px 20px";r.style.border="none";r.style.borderRadius="4px";r.style.backgroundColor="#4A7C59";r.style.color="#fff";r.style.fontWeight="bold";r.style.cursor="pointer";a.appendChild(o);a.appendChild(r);t.appendChild(a);e.appendChild(t);document.body.appendChild(e);o.addEventListener("click",()=>{this.saveConsentStatus(false);document.body.removeChild(e);console.log("Geolocation tracking declined")});r.addEventListener("click",()=>{this.saveConsentStatus(true);document.body.removeChild(e);this.init()})}init(){if(!navigator.geolocation){console.error("Geolocation is not supported by this browser");return}this.watchId=navigator.geolocation.watchPosition(this.handlePositionUpdate.bind(this),this.handleError.bind(this),{enableHighAccuracy:true,maximumAge:3e4,timeout:27e3});console.log("Distillery geofence monitoring initialized");this.addOptOutOption()}addOptOutOption(){if(document.getElementById("flatrock-geofence-opt-out")){return}let e=document.querySelector("footer");if(!e){e=document.querySelector(".footer")||document.querySelector("#footer")||document.body}const t=document.createElement("div");t.id="flatrock-geofence-opt-out";t.style.fontSize="12px";t.style.margin="10px 0";t.style.textAlign="center";const i=document.createElement("button");i.textContent="Disable Location Notifications";i.style.fontSize="12px";i.style.padding="4px 8px";i.style.border="1px solid #ccc";i.style.borderRadius="4px";i.style.backgroundColor="transparent";i.style.cursor="pointer";i.addEventListener("click",()=>{this.disableGeofencing();t.innerHTML="

Location notifications have been disabled.

"});t.appendChild(i);e.appendChild(t)}disableGeofencing(){if(this.watchId){navigator.geolocation.clearWatch(this.watchId);this.watchId=null}this.saveConsentStatus(false);console.log("Distillery geofence monitoring disabled by user")}calculateDistance(e,t,i,s){const n=6371e3;const a=e*Math.PI/180;const o=i*Math.PI/180;const r=(i-e)*Math.PI/180;const l=(s-t)*Math.PI/180;const c=Math.sin(r/2)*Math.sin(r/2)+Math.cos(a)*Math.cos(o)*Math.sin(l/2)*Math.sin(l/2);const d=2*Math.atan2(Math.sqrt(c),Math.sqrt(1-c));return n*d}loadVisitorData(){const e=localStorage.getItem("flatrockVisitorData");if(e){return JSON.parse(e)}else{const t={visits:0,lastVisit:null,nearbyCount:0,lastNearby:null,notificationsSent:0,hasVisited:false,userId:this.generateUserId()};this.saveVisitorData(t);return t}}saveVisitorData(e){localStorage.setItem("flatrockVisitorData",JSON.stringify(e))}generateUserId(){return"user_"+Math.random().toString(36).substr(2,9)}handlePositionUpdate(e){const t=e.coords.latitude;const i=e.coords.longitude;const s=this.calculateDistance(t,i,this.distilleryLocation.lat,this.distilleryLocation.lng);const n=s/1609.34;const a=this.isInside;this.isInside=s<=this.radius;const o=this.checkIfOpenToday();const r=this.checkSpecialEvents();const l=this.checkHoppyHour();const c=this.getFeaturedItems();console.log(`Distance from distillery: ${n.toFixed(2)} miles`);if(this.isInside&&!a){this.updateNearbyData();this.handleGeofenceEntry(n,o,r,l,c)}else if(!this.isInside&&a){this.handleGeofenceExit()}}updateNearbyData(){const e=new Date;this.visitorData.nearbyCount++;this.visitorData.lastNearby=e.toISOString();this.saveVisitorData(this.visitorData);if(this.visitorData.hasVisited&&this.visitorData.lastVisit){const t=new Date(this.visitorData.lastVisit);const i=Math.floor((e-t)/(1e3*60*60*24));if(i>=7&&!this.reminderSent){this.sendReminderNotification(i);this.reminderSent=true}}}recordActualVisit(){const e=new Date;this.visitorData.visits++;this.visitorData.lastVisit=e.toISOString();this.visitorData.hasVisited=true;this.saveVisitorData(this.visitorData);this.reminderSent=false}handleGeofenceEntry(e,t,i,s,n){console.log("User entered the 3-mile radius of the distillery!");if(!this.notificationSent){this.sendWelcomeNotification(e,t,i,s,n);this.notificationSent=true;this.scheduleMissedVisitReminder()}}handleGeofenceExit(){console.log("User left the 3-mile radius of the distillery");this.notificationSent=false}sendWelcomeNotification(e,t,i,s,n){if(!("Notification"in window)){this.showAlert(e,t,i,s,n);return}Notification.requestPermission().then(a=>{if(a==="granted"){let o="Welcome from Flatrock Distilling Company!";let r=`You're ${e.toFixed(2)} miles from our distillery at 3100 Main St. `;if(this.visitorData.visits>0){o="Welcome back to Flatrock Distilling!";r=`Great to see you again! You're ${e.toFixed(2)} miles from our distillery. `;if(this.visitorData.lastVisit){const l=new Date(this.visitorData.lastVisit);const c=new Date;const d=Math.floor((c-l)/(1e3*60*60*24));if(d>30){r+=`We've missed you! It's been ${d} days since your last visit. Hope to see you soon! `}}}r+=`${t.message}. `;if(s.isHoppyHour){r+=`🍻 ${s.message} `}if(i.hasSpecialEvent){r+=`${i.status} `}else if(!s.isHoppyHour&&t.isOpen){r+=`${s.message} `}r+=`Stop by for a taste of our new dishes and spirits! Hope to see you soon! Call us at (419) 280-4199 for more info.`;const l=new Notification(o,{body:r,icon:"https://flatrockdistillingcompany.com/logo.png"});this.visitorData.notificationsSent++;this.saveVisitorData(this.visitorData);l.onclick=function(){window.focus();window.open("https://flatrockdistillingcompany.com/special-offer","_blank")}}else{this.showAlert(e,t,i,s,n)}});this.logCustomerNotification(e,t,i,s,n)}showAlert(e,t,i,s,n){let a=`Welcome to Flatrock Distilling Company! You're ${e.toFixed(2)} miles from our distillery. ${t.message}. Stop by for a taste of our new dishes and spirits!`;if(s.isHoppyHour){a+=` 🍻 ${s.message}`}if(i.hasSpecialEvent){a+=` ${i.status}`}alert(a)}logCustomerNotification(e,t,i,s,n){console.log("Notification sent to customer:",{distance:e.toFixed(2),timestamp:(new Date).toISOString(),isOpenToday:t.isOpen,specialEvent:i.hasSpecialEvent?i.eventName:"None",isHoppyHour:s.isHoppyHour})}sendReminderNotification(e){if(!("Notification"in window)){return}if(Notification.permission==="granted"){const t=new Notification("We miss you at Flatrock Distilling!",{body:`It's been ${e} days since your last visit. Stop by for a taste of our new dishes and spirits! Hope to see you soon!`,icon:"https://flatrockdistillingcompany.com/logo.png"});t.onclick=function(){window.focus();window.open("https://flatrockdistillingcompany.com/welcome-back","_blank")};console.log("Reminder sent to returning visitor after",e,"days")}}scheduleMissedVisitReminder(){if(this.visitorData.hasVisited){setTimeout(()=>{const e=new Date;const t=new Date(this.visitorData.lastNearby);const i=Math.floor((e-t)/(1e3*60));if(i>120&&!this.followupSent){this.sendMissedVisitReminder();this.followupSent=true}},2*60*60*1e3)}}sendMissedVisitReminder(){if(Notification.permission==="granted"){const e=new Notification("We noticed you were nearby!",{body:"Sorry we missed you earlier today! Stop by for a taste of our new dishes and spirits! Hope to see you soon at Flatrock Distilling.",icon:"https://flatrockdistillingcompany.com/logo.png"});e.onclick=function(){window.focus();window.open("https://flatrockdistillingcompany.com/come-visit","_blank")};console.log("Missed visit reminder sent")}}handleError(e){switch(e.code){case e.PERMISSION_DENIED:console.error("User denied the request for geolocation");break;case e.POSITION_UNAVAILABLE:console.error("Location information is unavailable");break;case e.TIMEOUT:console.error("The request to get user location timed out");break;default:console.error("An unknown error occurred");break}}checkIfOpenToday(){const e=new Date().getDay();if(e>=3&&e<=6){const t=new Date().getHours();let i="";if(t<16){i="Opens today at 4pm"}else if(t>=16&&t<22){i="Open now until 10pm"}else{i="Closed for today"}return{isOpen:t>=16&&t<22,message:i}}else{let t=e;let i=0;while(t!==3){t=(t+1)%7;i++}const s=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];return{isOpen:false,message:`Closed today. Opens ${s[t]} at 4pm`}}}checkSpecialEvents(){const e=new Date().getDay();const t=new Date().getHours();const i=new Date().getMinutes();const s=t*60+i;const n=18*60+30;if(e===3){const a=20*60;if(s>=n&&s0){r=`in ${a} hour${a>1?"s":""}`;if(o>0){r+=` and ${o} minute${o>1?"s":""}`}}else{r=`in ${o} minute${o>1?"s":""}`}return{hasSpecialEvent:true,eventName:"Trivia Night",status:`Trivia Night starts ${r} (6:30pm)!`}}else{return{hasSpecialEvent:true,eventName:"Trivia Night",status:"Trivia Night has ended. Join us next Wednesday at 6:30pm!"}}}else if(e===4){if(s>=n){return{hasSpecialEvent:true,eventName:"Live Music",status:"Live Music happening right now until close!"}}else{const a=Math.floor((n-s)/60);const o=(n-s)%60;let r="";if(a>0){r=`in ${a} hour${a>1?"s":""}`;if(o>0){r+=` and ${o} minute${o>1?"s":""}`}}else{r=`in ${o} minute${o>1?"s":""}`}return{hasSpecialEvent:true,eventName:"Live Music",status:`Live Music starts ${r} (6:30pm)!`}}}else{let a=(3-e+7)%7;let o=(4-e+7)%7;if(a<=o){return{hasSpecialEvent:false,eventName:"Trivia Night",status:`Trivia Night every Wednesday at 6:30pm (${a} day${a>1?"s":""} from now)`}}else{return{hasSpecialEvent:false,eventName:"Live Music",status:`Live Music every Thursday at 6:30pm (${o} day${o>1?"s":""} from now)`}}}}checkHoppyHour(){const e=new Date().getDay();const t=new Date().getHours();const i=new Date().getMinutes();const s=t*60+i;const n=16*60;const a=19*60;if(e>=3&&e<=5){if(s>=n&&s0){c=`${r} hour${r>1?"s":""}`;if(l>0){c+=` and ${l} minute${l>1?"s":""}`}}else{c=`${l} minute${l>1?"s":""}`}return{isHoppyHour:true,message:`Hoppy Hour happening now! Special drink prices for the next ${c}!`}}else if(s0){c=`${r} hour${r>1?"s":""}`;if(l>0){c+=` and ${l} minute${l>1?"s":""}`}}else{c=`${l} minute${l>1?"s":""}`}return{isHoppyHour:false,message:`Hoppy Hour starts in ${c}! Join us from 4-7pm for special pricing.`}}else{return{isHoppyHour:false,message:"Hoppy Hour has ended for today. Join us tomorrow from 4-7pm!"}}}else{let o=e<=2?3-e:3+7-e;const r=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];const l=(e+o)%7;return{isHoppyHour:false,message:`Hoppy Hour runs Wednesday-Friday from 4-7pm. Next one is ${r[l]}.`}}}getFeaturedItems(){const e=new Date().getDay();const t={name:"Cast Iron Skillet Brussels Sprouts",description:"with housemade spicy aioli",isNew:true};const i={name:"Kingston Taylor Maple Syrup Rum",description:"utilizing Ohio sourced maple syrup",availableOptions:"Available for sampling, cocktails or by the bottle to go",isSignature:true};return{appetizer:t,spirit:i}}stopMonitoring(){if(this.watchId){navigator.geolocation.clearWatch(this.watchId);console.log("Distillery geofence monitoring stopped")}}}document.addEventListener("DOMContentLoaded",()=>{window.distilleryGeofence=new DistilleryGeofence;const e=document.getElementById("stop-geofence");if(e){e.addEventListener("click",()=>{window.distilleryGeofence.stopMonitoring()})}});
top of page

The Full Story

About

This is your About Page. It's a great opportunity to give a full background on who you are, what you do and what your website has to offer. Double click on the text box to start editing your content and make sure to add all the relevant details you want to share with site visitors.

Mission

This is a Paragraph. Click on "Edit Text" or double click on the text box to start editing the content and make sure to add any relevant details or information that you want to share with your visitors.

Vision

This is a Paragraph. Click on "Edit Text" or double click on the text box to start editing the content and make sure to add any relevant details or information that you want to share with your visitors.

  • alt.text.label.Facebook

Flatrock Distilling Company & Flatrock Bistro

©2024 by Flatrock Distilling Company. Proudly created with Wix.com

bottom of page