We have done some visitor level custom variables on our website (we used all indexes from 1 to 5), and now we are using index 1 for another custom variable name (no code to set custom variable to the previous variable name), but we encountered a problem: we still see few data 开发者_开发问答for the previous custom variable name.
We think it should because the previous custom variable name of index 1 is still saved in the cookie of some user's browsers. So we find the function _deleteCustomVar(index) which can delete the custom variable by indexes.
My goal is, no new data for previous custom variable name for that index in the future, but new custom variable name can still use that index.
I have some questions on the usage of this function:
when we call _deleteCustomVar(index), how much work it will do? remove the custom variable index in user's cookie, or send a request to google analytics website?
as i mentioned above, if we are already using the same index for a new custom variable name, can we still call _deleteCustomVar function to remove the previous custom variable name? if we cannot, what should i do to achieve my goal?
_deleteCustomVar
does not send its own request to Google Analytics. (Neither does_setCustomVar
). Instead,_deleteCustomVar
just removes the variable value from the cookie if it's a visitor level custom variable, and deletes the custom variable from the current page's scope for future requests on that page. It also takes effect for all future hits to Google Analytics.If you set a new custom variable to an index that already has a custom variable in it for that particular user (at that time), it overwrites the value.
setCustomVar
has the effect of doing both_deleteCustomVar
andsetCustomVar
for that new value at the same time, since Google Analytics only allows one custom variable per variable slot.
It's important to note that deleteCustomVar
does nothing for past data that has been sent with that variable. (In effect, it will only reduce the number of pageviews associated with that custom variable, and for visitor level variables, not be associated with any future visits. Deleted or overwritten variables that have already sent hits to Google Analytics will still be associated with that session in some way.)
As to why you might end up with 'old' variable values still showing up, well, its complicated. Some of Google Analytics's associations are based on users; some are based on sessions, and some pageviews. It's likely that any data discrepancies are due to a misunderstanding.
So, if a user, during a single session, has 3 different custom variables set and sent on hits for the same slot, and you create an advanced segment (which segments by sessions) for any one of those variables, that session will come through.
Same scenario, if you're counting visits that have a custom variable, the counts can overlap, such that you could have 10 visits each for each of the 3 variables of the same slot, but only 10 visits total.
精彩评论