Expand my Community achievements bar.

Join us in celebrating the outstanding achievement of our AEP Community Member of the Year!

Adobe rule not pushing custom variable data in Google Ads

Avatar

Level 1

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>

1 Reply

Avatar

Community Advisor

Hi @HarpreetLo 

when using the Adobe Client Data Layer and trying to access data element which may be set based on a push to the ACDL, always send the event as second parameter.

_satellite.getVar('ACDL - storefront', event);

As a matter of fact, I would always send it with any getVar call, at least I have not seen an occasion when it caused problems.

Cheers from Switzerland!