// Function to capture URL parameters
function getQueryParam(param) {
let urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
// Retrieve UTM parameters from URL
let campaign = getQueryParam("utm_campaign");
let adGroup = getQueryParam("utm_adgroup");
let ad = getQueryParam("utm_ad");
// Create a dynamic WhatsApp message
let customMessage = `Hello, I’m interested after seeing your ad - Campaign: ${campaign || "N/A"}, Ad Group: ${adGroup || "N/A"}, Ad: ${ad || "N/A"}`;
// Wait for the page to load, then modify the WP Chat App link
document.addEventListener("DOMContentLoaded", function() {
let whatsappLinks = document.querySelectorAll(".wpca-button a"); // WP Chat App typically uses this class for buttons
whatsappLinks.forEach(function(link) {
link.href = link.href.split('?')[0] + "?text=" + encodeURIComponent(customMessage);
});
});