Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event tracking empty label string

I have a function which handles tracking of a certian event, like so:

var trackAddress = function (providedProduct, searchedProduct) {
    _trackEvent('Address found', providedProduct, searchedProduct);
}

Now what will happen if searchedProduct is undefined or an empty string?

The thing is, in Google Analytics I can see that the sum of all event actions is equal to the total number of events. That is not the case in event labels.

What could be the cause for this?

like image 236
Björn Andersson Avatar asked Sep 29 '22 07:09

Björn Andersson


1 Answers

I'm sure you know this, but for the sake of argument this is the anatomy of an event tracker:

_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)
  • category (required): The name you supply for the group of objects you want to track.
  • action (required): A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
  • label (optional): An optional string to provide additional dimensions to the event data.
  • value (optional): An integer that you can use to provide numerical data about the user event.
  • non-interaction (optional): A boolean that when set to true, indicates that the event hit will not be used in bounce-rate calculation.


Now in case a required parameter is missing (like action in your case) there's must be a mechanism within Google Analytics that will invalidate the event altogether. Conversely, an optional parameter, won't affect the event tracking but rather the report. To sum up, the result is the same: Loss of data.


A possible way around this to provide default parameters for your function arguments like so:

providedProduct = typeof a !== 'undefined' ? providedProduct : "defaultValue";


Further Reading: Setting Up Event Tracking

like image 174
carlodurso Avatar answered Oct 04 '22 02:10

carlodurso