-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Analytics assumes it is a new user at each request #124
Comments
You have to save the cid and re-use it. This REALLY screwed me over as I assumed it would be automatic and I had mmonths of tracking data that were useless! |
@burtonator yeah, a new one is generated at every request, but even when I provided a front-end (cached) uuid it would consider it as a new user when using this uuid from the server. My current code is this: const visitor = ua(this.googleAnalyticsVisitor.tid, this.deviceId, {
uid: this.deviceId,
}); But still, doesn't work as expected. If you managed to have it working I'm very much interested, but beware and make sure you check it twice because I've tried for hours and didn't find a proper way yet. |
I"m setting cid... not uid . Try that? I know that uid is supposed to work though. maybe try with cid as deviceId? |
I tried it all (for all I know), if you have a working code I'd interested to take a peak! |
One thing I noticed is that the User Agent isn't actually tracked by default so I added that as well. This is from the browser and not node. In Electron it's called the 'renderer' context. |
I tried following your way, went from this: const category = this.getGoogleAnalyticsCategory();
const action = this.getGoogleAnalyticsAction();
const label = this.getGoogleAnalyticsLabel();
const value = this.getGoogleAnalyticsValue();
const path = this.getGoogleAnalyticsPath();
const visitor = ua(this.googleAnalyticsVisitor.tid, this.deviceId, {
uid: this.deviceId,
});
visitor.event(
category,
action,
label,
value,
{ p: path }, // See "page path" at https://github.com/peaksandpies/universal-analytics/#event-tracking
(err) => {
if (err) {
this.logger.error(err, 'sendGoogleAnalyticsStatistics:error');
Raven.captureMessage(err, { level: 'error' });
}
},
); to this: const category = this.getGoogleAnalyticsCategory();
const action = this.getGoogleAnalyticsAction();
const label = this.getGoogleAnalyticsLabel();
const value = this.getGoogleAnalyticsValue();
const path = this.getGoogleAnalyticsPath();
const visitor = ua(this.googleAnalyticsVisitor.tid, {
cid: this.deviceId,
uid: this.deviceId,
headers: {},
}).debug(process.env.NODE_ENV !== 'production');
const eventParams = {
eventCategory: category,
eventAction: action,
eventLabel: label,
eventValue: value,
documentPath: path,
// userAgentOverride: userAgent,
applicationVersion: `${process.env.GIT_COMMIT_VERSION || ''}`
};
visitor.event(eventParams).send((err) => {
if (err) {
this.logger.error(err, 'sendGoogleAnalyticsStatistics:error');
Raven.captureMessage(err, { level: 'error' });
}
}); The first version creates a new user at every event hit, but the second doesn't work at all. No event are received from GA, nothing. |
Finally I figured it out, the lib really doesn't help to pinpoint issues const visitor = ua(this.googleAnalyticsVisitor.tid, this.deviceId, {
uid: this.deviceId,
strictCidFormat: false, // Using non-strict for compatibility with devices using UUID v1 (used at the beginning, can be safely removed after May 2019)
}).debug(process.env.NODE_ENV !== 'production');
visitor.event(
category,
action,
label,
value,
{ p: path }, // See "page path" at https://github.com/peaksandpies/universal-analytics/#event-tracking
(err) => {
if (err) {
this.logger.error(err, 'sendGoogleAnalyticsStatistics:error');
Raven.captureMessage(err, { level: 'error' });
} else {
this.logger.info(`Response received from GA`, 'sendGoogleAnalyticsStatistics:success');
this.logger.debug(err);
}
},
); My errors were:
|
Glad you found out about the UUID v4 issue.. I was actually not even going to use UUID so maybe I got lucky,. |
@burtonator There is one last thing I haven't figured out yet, and you likely have the same issue. |
@Vadorequest I didn't resolve this. I just don't use that feature. I'm sure I will encounter this at some point. I also realized that my code doesn't actually appear to work. I think I'm seeing the problem you're seeing where the stat data is being discarded. I made the changes I discussed above and basically nothing is making it into the GA console even though the agent is saying it's sending the stats. So I think it's silently discarding them (which is pretty evil) ... I don't necessarily think this is universal-analytics' fault but I'm not certain yet. I enable debug and I can see it's sending the values but they're not turning up in the GA console. This is maddening as I've been aggressively trying to analyze my metrics only for them to become completely invalidated. I think the only real solution moving forward is to use two analytics platforms. This way if one breaks I can compare it to the other. |
Well, I have been very precautious about it and did check that the data were saved properly, and it currently does. But it doesn't when the UUID has the wrong format, for instance, and in such case it does fail silently. It took me a while to figure everything out and debug and such, and I wish I had enabled debug much sooner to be honest! |
I have the same issue, I am seeing double events from the client and the server @Vadorequest I dont want to track on the server side if the client is doing it, have you managed to figure out how to conditionally track |
No, I haven't. My analytics therefore sucks, and I want to stop using GA and looking for a better alternative that is more flexible/reliable. IMHO, GA is a very old tool that has tons of features and is way too complex and way too little flexible for proper use cases, not only the JS API sucks, but you can't even manipulate your data as easily as it should be. It's too complicated for its own good, probably because it's decades-old and loads tons of useless stuff. |
And not to mention, despite all this you got regex parsing referrer spam bots everywhere in your dashboard which has no automated filtering mechanism |
Even you provide a If you want to set non-UUID as const visitor = ua(TID, userid, {strictCidFormat: false}); Then, the console.log(visitor);
---
{
_queue: [],
options: { strictCidFormat: false },
_context: {},
_persistentParams: {},
tid: 'UA-14523290-4',
cid: 224581513
} But in the case of a chatbot, https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#user |
if you connect uid (set('uid')), maybe analytics returning user count from the user_id report. |
GA count each request sent from the backend as a new User:
I'm building a chatbot, and each message sent by the user counts as a new user. I really don't get why and everything should be working fine because I set the
uid
(user id) andcid
(client id) using a variable corresponding to the device id.Here is some source code:
Here are the logs
I don't get why it doesn't work properly.
The text was updated successfully, but these errors were encountered: