I asked this question over on StackOverflow, and someone suggested that I might have better luck here, so here it is:

I am working on an app that will be running on a single touchscreen device in a single location. The device is connected to the internet, and the app is essentially a web app (it will be hosted locally in IIS on a Windows 10 machine), so we want to use Google Analytics to track usage.

After a certain amount of inactivity, the app will go into an "idle" mode.

I think it's fair to assume that if there was no user interaction for long enough for the app to go idle, the person has probably walked away from the device, and when there is more interaction and it comes out of idle mode, it must be a new user.

Therefore, I want to track analytics as if it were a different user, which means I need to reset the _ga and _gid cookies to get new user IDs.

How can I do that?

I've tried just deleting the old cookies, and pushing more data to window.dataLayer, in the hopes that the GA script would see that there were no cookies and recreate them. No luck there.

I've tried deleting the cookies, clearing window.dataLayer, and then deleting the original script tag and re-adding a new script tag to reload the GA script to try and get it to recreate the cookies that way. Again no luck, although I see that on the second load it looks like it's being loaded from the cache, so I'm wondering if I have to somehow clear the GA script from cache too.

The only way I've been able to get it to work is to delete the cookies and do a hard refresh of the browser. But that's not something I want to do, because a refresh would interrupt the user experience.

So before I go down the path of trying to delete the script from cache, I thought I'd ask - is there a way to reset the _ga and _gid cookies to simulate a new user, without refreshing the browser?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.