I have the Google adwords event snippet implemented in an rule, but of the 4 custom variables listed in the code, only 1 of them passes back data in Google Ads - do you know why this is? The only successful variable passing back data is "var regionName" - the 3 unsuccessfully passing any data back are "var transactionID", "var order", "var currencyCode" - I don't know why this is.
Code pasted below:
<!-- Event snippet for Transaction conversion page -->
<script>
try {
// Directly extract product price from the page element
var priceElement = document.querySelector('.amount .price'); // Adjust selector based on your HTML structure
if (!priceElement) {
throw new Error("Price element not found on the page.");
}
var productPriceText = priceElement.textContent.trim();
var productPrice = parseFloat(productPriceText.replace(/[^\d.-]/g, ''));
if (isNaN(productPrice)) {
throw new Error("Unable to extract valid product price.");
}
// Data element for the currency code
var currencyCode = (_satellite.getVar('ACDL - currency code') || _satellite.getVar('ACDL - storefront').storeViewCurrencyCode).toLowerCase(); // Convert to lowercase
// Data element for the transaction ID
var order = _satellite.getVar('ACDL - order');
var transactionID = order ? order.orderId.toString() : '';
// Data element for the region name
var regionName = (_satellite.getVar('ACDL - storefront').websiteCode || '').toLowerCase();
// Sending the conversion event to Google Ads using gtag
gtag('event', 'conversion', {
'send_to': 'AW-963991755/2T-CCK3prVYQy7HVywM',
'value': productPrice,
'currency': currencyCode,
'transaction_id': transactionID,
'region_name': regionName // Adding region name as a custom variable
});
console.log("Google Ads conversion event sent successfully.");
} catch (error) {
console.error("Error sending Google Ads conversion event:", error.message);
}
</script>