Every day we track data from various platforms like Google Ads, GA4, Meta Pixel, etc, they recommend sending the Transaction ID(order ID) for accurate tracking and reporting, but sometimes the Transaction ID does not appear on the confirmation page, and you can't track it,
In this situation, how we can retrieve it from the confirmation page URL when it's not present or when you're not using the dataLayer?
in this case, we can track the order ID from the URL using Custom JavaScript, (if it's available in your thank you page URL )
Process to implement
1️)Go to your Google Tag Manager
2️)Create page URL Variable (this variable you have to add in the javascript code)
3️)Again create a custom javascript variable and paste this code (add page URL Variable in this code)
function() {
var successful_page_url = {{Page URL}};
var orderID = successful_page_url.split("/")[5];
return orderID;
}
4️)Edit the split number according to your thank you page URL
5️)Click Save
6️)Go to preview and check it
7️)Now you can add this variable to your required event parameters