the store I manage sends data to Google Analytics - Enhanced E-Commerce using the following code and not via dataLayer.
ga('ec:setAction', 'purchase', {
'id': '1014',
'revenue': '69.06',
'shipping': '0.00',
'tax': 0
});
ga('send', 'pageview');
Now, how can I add the value of the 'revenue' to a Tag Manager variable?
I tried the following code in a Custom Java Script Variable but it's not working.
ga(function() {
var test = ga.getByName('revenue');
return test;
})
Now exactly because you didn't push the revenue to the DL, you won't be able to access it in GTM.
You could, technically, still get it by some obscure overridal of the ga() function, but that would be an overkill.
Another option would be trying to parse the value from DOM or looking for it in the global scope.
The best route from here, however, would be explicitly pushing the information you need to the dataLayer to make it available for GTM. That is one important benefit of using DL-based EEC tracking: you have all the information available in case it's needed for other tags. Third-party tags often want to know things like totals, transaction ids and such for proper attribution.
Having said that, I would suggest never calling the ga function directly. Having all tracking in one place (GTM/DL) makes it a lot easier to debug. Especially for the people who come after you.