I've got a javascript program that is deployed as a custom HTML GTM tag that loads Javascript. The Javascript dynamically gets custom dimension index and value pairs. The following Javascript is what pushes the data to Google Analytics:
ga(function (tracker) {
// ... code to figure out the dimension index & value ... //
// Assuming Index & Value for custom dimension are now known
var dimData = {};
dimData["dimension" + index] = value;
dimData["nonInteraction"] = true;
var action = "Set " + index + " to " + value;
var trackerName = ga.getAll()[0].get('name');
ga(trackerName + '.send', 'event', 'Dimension', action, dimData);
}
I can see Events coming through with dimension data but I'm not seeing the custom dimension data. What might be causing this?
Update: The GTM tag has Universal Analytics set to fire before it, the HTML includes an external <script> library that loads configuration (dimensions with which data to look for), parse the output and then attempts to send the data to Google Analytics. I don't think it's a race condition, its wrapped in ga(function (tracker) callback. We don't know the dimensions ahead of time.
gaobject before it is actually defined due to the asynchronous nature of loading the analytics library, so you might be getting something like 'ga.getAll is not a function'. You'll either need a callback or you could set your tag to fire later like ongtm.dom.