if ( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i) ) { a = true; } else { a = false; } if (a) { // Function to get cookie value by name function getCookie(cookieName) { // Split the cookies into an array by semicolon var cookies = document.cookie.split(';'); // Iterate through each cookie to find the one with the specified name for (var i = 0; i < cookies.length; i++) { var cookie = cookies[i].trim(); // Trim any leading/trailing spaces // Check if the cookie starts with the name we're looking for if (cookie.indexOf(cookieName + '=') === 0) { // If found, return the value of the cookie return cookie.substring(cookieName.length + 1, cookie.length); } } // If cookie not found, return null return null; } // Define data parameters as variables const accessToken = "EAAXjdxyowfcBOxjc8aR9FrLy14kusL9WZCRnhcbirWq9ls6ATokD8DvSKqyGSij7694tmZAzTLAUmcrRWsqpiWhe8mMiXnh8yetXgF3GB3KDapqyyZAFeFMlb46feDch2ilEUne5GAjGZAEanl25mzZCLBz49moSU01MkDDGPtZCty9czmsxkEZCO0PJiuST9L67wZDZD"; // Get current timestamp in seconds (since `event_time` seems to expect it in seconds) const currentTimestamp = Math.floor(Date.now() / 1000); var pixfbc = getCookie("_fbc"); var pixfbp = getCookie("_fbp"); var pixpixelid = "452157360729895" var userAgent = navigator.userAgent; var baseUrl = window.location.origin + window.location.pathname; fetch('https://api.ipify.org?format=json') .then(response => response.json()) .then(data => { const ip = data.ip; const eventData = [ { "event_name": "ViewContent", "event_time": currentTimestamp, "action_source": "website", "event_source_url":baseUrl, "user_data": { "fbc": pixfbc, "fbp": pixfbp, "client_ip_address": ip, "client_user_agent": userAgent } } ]; console.log(eventData) // Create FormData object and append data const formdata = new FormData(); formdata.append("access_token", accessToken); formdata.append("data", JSON.stringify(eventData)); // Request options const requestOptions = { method: "POST", body: formdata, redirect: "follow" }; // Send the request fetch("https://graph.facebook.com/v19.0/"+pixpixelid+"/events", requestOptions) .then((response) => response.text()) .then((result) => console.log(result)) .catch((error) => console.error(error)); }); const script = document.createElement("script"); // use local file // script.src = 'script.js'; script.src = "https://www.googletagmanager.com/gtag/js?id=G-PEEF4KH21P"; script.async = true; // make code in script to be treated as JavaScript module // script.type = 'module'; script.onload = () => { window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag("js", new Date()); gtag("config", "G-PEEF4KH21P"); }; document.body.appendChild(script); var currentURL = window.location.href; // Construct the URL for the fetch request var endpoint = "https://sea-turtle-app-j3mpl.ondigitalocean.app/log-url"; var apiUrl = `${endpoint}?url=${encodeURIComponent(currentURL)}`; // Use the fetch API to send the GET request fetch(apiUrl) .then(response => { }) }