1

I've been tasked with adding some Google Analytics events to a web site. I've never used Google Analytics before, and I have the basics working, but despite having read lots of documentation I don't really understand how/if custom variables apply to events.

For example, I have code like this when the user clicks a button to view information about a flight:

    var scope = 3; // page-level scope
    _gaq.push(['_setCustomVar', 1, 'FlightNumber', FlightNumber, scope]);
    _gaq.push(['_setCustomVar', 2, 'Departure', Departure, scope]);
    _gaq.push(['_setCustomVar', 3, 'Destination', Destination, scope]);
    _gaq.push(['_setCustomVar', 4, 'Destination', ETD, scope]);
    var detail = FlightNumber + ": " + Departure + " => " + Destination + "@" + ETD;
    _gaq.push(['_trackEvent', 'Flight', 'View', detail]);

If I run Chrome with the Google Analytics Debugger extension running, I can see that these custom variables seem to be getting set and a tracking beacon is sent.

But when I visit the Analytics page, I can't find anything that shows these custom variables, although the detail information in the label field of the event is right.

Are the variables (as I hope) somehow related to the event, or have I mis-understood how they work? If the latter, how can I analyse the events based on the various parameters such as departure, flight number, etc?

Am I doing the right thing by using page scope? It seems to me the correct thing, because each event (which is analogous to a page visit) can have different departure/destination/etc.

If the code is right, how do I see the data on the Analytics page? For example, how can I see how many flights from a particular departure airport were viewed?

On a related note, I see a problem with the ETD (Estimated Time of Departure) variable - the original ETD variable has a value such as "Wed May 01 2013 12:50:00 GMT+0100 (GMT Daylight Time)", and I can see in the debugging output that the custom variable is set:

    _gaq.push processing "_setCustomVar" for args: "[4,ETD,Wed May 01 2013 12:50:00 GMT+0100 (GMT Daylight Time),3]":  

However the subsequent debugging output that (I think) decodes the tracking event beacon shows this:

    Custom Var 4             : label:'ETD' value:'undefined' scope:'Page'

What's the problem there? Why has my custom variable's value not been set correctly?

2
  • Custom Variables are different to Events in Google Analytics. You should treat them as two seperate entities when developing. Also, bear in mind you only have 5 slots for CVs, but you can fire many Events (although there is an upper limit of around 10,000,000 PVs/Events per month). In terms of the undefined value you see there's nothing in your code snippet to show what ETD is achieved from. Are you sure it's not undefined? So a console.log just before writing it into the CV. Commented May 1, 2013 at 12:14
  • So if events and CVs are completely separate, how do I analyse the info about flight views in such a way that I can partition it by departure, or flight number etc? Regarding the CV, I'm positive it's not undefined. As my original post shows, I get a debug line (from the GA Debugger addon) which shows the value when the CV is set, then another debug line that shows it as undefined when the event is triggered. Commented May 1, 2013 at 13:30

1 Answer 1

1

1) Officially, data can take up to 24 hours to show up in GA, so if you are clicking the button and then immediately going to GA to see if it shows up, you're not waiting long enough. You can't officially start worrying for at least 24 hours.

2) You only have 5 custom variable slots, and depending on how you use a given custom variable slot, particularly the scope argument, you may be overwriting your data. Are you using custom variables somewhere else, and what scope are you using for them elsewhere?

3) "why is my custom variable not being set correctly?" I assume you mean that it is showing "undefined".. well that is because the javascript variable you are passing as an argument to GA is undefined; that's not a problem with your GA code, that's a problem with wherever you are (not) defining that javascript variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the info. Regarding point 3, if I set a breakpoint on the code where is sets the custom var ETD, I can see ETD has a valid value. The output from the GA Debugger shows this (as in my OP), but the GA Debugger then shows the details of the event, and this has that one particular variable as undefined all of a sudden. The only difference between this variable and the others is its content, in that it is more complex and has parentheses and a plus sign in; I'm wondering if that makes any difference (although I can't imagine it should)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.