adam0101
adam0101

Reputation: 30995

How do I update a custom variable for Google Analytics?

I have Google Analytics on a single-page-app. One of my custom variables is a SessionId. If the user goes away for an hour and comes back, I want to update the SessionId with a new value. This is how I set it at first:

_gaq.push(['_setCustomVar', 2, 'SessionId', 'u902832902384', 2]);

If I call that same code again with a different value, will it update the variable or do I have to update it a different way?

Upvotes: 0

Views: 38

Answers (1)

nyuen
nyuen

Reputation: 8907

You can use the same code with the new value. Some more info here:

Call the _setCustomVar() function when it can be set prior to a pageview or event GIF request. In certain cases this might not be possible, and you will need to set another _trackPageview() request after setting a custom variable. This is typically only necessary in those situations where the user triggers a session- or visit-level custom var, where it is not possible to bundle that method with a pageview, event, or ecommerce tracking call.

Source: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables

Upvotes: 1

Related Questions