function checkCookie(cookieName) {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let cookie = cookies[i].trim();
if (cookie.indexOf(cookieName + '=') === 0) {
return true;
}
}
return false;
}
function getCookie(name) {
const nameEQ = name + '=';
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return decodeURIComponent(c.substring(nameEQ.length, c.length));
}
}
return null;
}
var cookie = '69dfedc98e286';
if (checkCookie('smdDNI')) {
cookie = getCookie('smdDNI');
} else {
document.cookie = 'smdDNI=69dfedc98e286;path=/; max-age=2592000;';
}
document.addEventListener('DOMContentLoaded', function() {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
// Find the first tag with href starting with tel:
let replaced_number = '';
const telLink = document.querySelector('a[href^="tel:"]');
if (telLink) {
// Get the phone number from the href, stripping 'tel:' and whitespace
replaced_number = telLink.getAttribute('href').replace(/^tel:/i, '').replace(/\s+/g, '');
}
const keyword = urlParams.get('keyword');
const matchtype = urlParams.get('matchtype');
const device = urlParams.get('device');
const network = urlParams.get('network');
const campaignid = urlParams.get('campaignid');
const gclid = urlParams.get('gclid');
const url = window.location.href;
// Toggle for phone number replacement
var enableReplacement = false;
var hasEligibleNumbers = false;
if(enableReplacement && hasEligibleNumbers && gclid != ''){
messageElements.forEach(function(element) {
element.innerHTML = '';
});
document.querySelectorAll('a').forEach(function(link) {
const href = link.getAttribute('href');
if (href && href.toLowerCase().startsWith('tel:')) {
link.setAttribute('href', 'TEL:');
link.textContent = '';
}
});
}
const postData = {
keyword: keyword,
matchtype: matchtype,
device: device,
network: network,
campaignid: campaignid,
gclid: gclid,
number: undefined,
session: cookie,
replaced_number: replaced_number,
url: url
};
fetch('https://app.smartmarketdental.com/api/dni/save/TEL:', {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=UTF-8'
},
body: JSON.stringify(postData)
})
.then(response => {
if (!response.ok) {
console.log('error');
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch(error => {
console.log('Error:', error);
});
});