Skip to content
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

How to clear user traits with old version of Analytic.js #923

Closed
Quang810 opened this issue Aug 9, 2023 · 1 comment
Closed

How to clear user traits with old version of Analytic.js #923

Quang810 opened this issue Aug 9, 2023 · 1 comment

Comments

@Quang810
Copy link

Quang810 commented Aug 9, 2023

My company integrated analytics.js (the old version, not 2.0) into our code base a few years ago. Now we want to clear the traits of users when they log out because we don't want to store the personal information of users in local storage. Through reading the documentation, I am aware that we can clear the traits in the cache by passing an empty object into the traits method:

You can pass an empty object to the traits object to clear all cached traits for a User or Group.

Traits are cached by default when you call the Identify and Group methods. You can clear the traits object for the user or group by passing traits an empty object:

analytics.user().traits({});
analytics.group().traits({});

I'm aware that this is from Analytics.js 2.0 documentation, but I have checked the source code of Analytics.js (the archive repo) and I noticed that the old version also exposes the user() method, which I assume that we can use that method to access to current user:

...Analytic.js code
/**
 * Return the current user.
 *
 * @return {Object}
 */

Analytics.prototype.user = function() {
  return user;
};
...

However, I don't see such method listed in the analytic.js snippet

...snippet
// A list of the methods in Analytics.js to stub.
  analytics.methods = [
    'trackSubmit',
    'trackClick',
    'trackLink',
    'trackForm',
    'pageview',
    'identify',
    'reset',
    'group',
    'track',
    'ready',
    'alias',
    'debug',
    'page',
    'once',
    'off',
    'on',
    'addSourceMiddleware',
    'addIntegrationMiddleware',
    'setAnonymousId',
    'addDestinationMiddleware'
  ];
...

So can we clear the user trait by passing in an empty object like the documentation said, or is that feature only available in Analytic.js 2.0? Thank you.

@silesky
Copy link
Contributor

silesky commented Aug 10, 2023

Hey @Quang810

The snippet methods are not relevant if you call analytics.ready(() => analytcs.user.... That said, I am not sure, and I recommend you test to find out.

The old version of analytics.js has been end of lifed for well over a year; this repo is just for analytics next, as such, this is not a place for classic support. I strongly urge you to upgrade.

Please contact Segment support through the website if you have further questions about migration.

@silesky silesky closed this as completed Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants