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

setAnonymousId not persisting when calling track with @jitsu/js #1060

Closed
otaku-tekkurai opened this issue Nov 15, 2023 · 1 comment
Closed

Comments

@otaku-tekkurai
Copy link

Description:

I am attempting to set the anonymous ID using setAnonymousId, but when I call track("EVENT_1", {}), the anonymous ID is null or something different. However, the anonymous ID of EVENT_2 is as expected.

Code Snippet:

const { jitsuAnalytics } = require("@jitsu/js");
const { v4: uuidv4 } = require("uuid");

const config = {
    host: "http://jitsu-develop.d.in/",
    writeKey: "your_write_key_here",
    debug: true
};

const setupJitsu = async () => {
 try {
   const client = jitsuAnalytics(config);

   if (client) {
       const anonymousId = uuidv4();
       console.log("Anonymous ID:", anonymousId);

       await client.setAnonymousId(anonymousId);
       console.log("anonymousId setup");

       await client.track("EVENT_1", {});
       console.log("Event 1 tracked"); // not as expected

       await client.track("EVENT_2", {});
       console.log("Event 2 tracked"); // as expected
   }
 } catch (error) {
     console.error("Error setting up Jitsu client:", error);
 }
}

setupJitsu()

Logs:

[JITSU EMPTY RUNTIME] Get storage item __user_id=undefined
[JITSU EMPTY RUNTIME] Get storage item __anon_id=undefined
[JITSU EMPTY RUNTIME] Get storage item __user_traits=undefined
Anonymous ID: 69592ef2-1db7-4713-9f17-8d166aad014a
anonymousId setup
[JITSU EMPTY RUNTIME] Get storage item __user_id=undefined
[JITSU EMPTY RUNTIME] Get storage item __anon_id=undefined
[JITSU EMPTY RUNTIME] Get storage item __user_traits=undefined
[JITSU EMPTY RUNTIME] Set storage item __anon_id="cc0b9784-469c-42c1-8048-7e29035b3dc0"
[JITSU EMPTY RUNTIME] Set storage item __anon_id="69592ef2-1db7-4713-9f17-8d166aad014a"
[JITSU] Initializing Jitsu plugin with config:  {"writeKey":"***:***","host":"http://jitsu-develop.d.in","debug":true,"fetch":null,"echoEvents":false}
[JITSU EMPTY RUNTIME] Get storage item __user_traits=undefined
[JITSU] http://jitsu-develop.d.in/api/s/track replied 200. Original payload:  {
  "type": "track",
  "event": "EVENT_1",
  "properties": {},
  "userId": null,
  "anonymousId": "cc0b9784-469c-42c1-8048-7e29035b3dc0",
  "timestamp": "2023-11-15T23:45:30.295Z",
  "sentAt": "2023-11-15T23:45:30.295Z",
  "messageId": "1glauk7uyuovpmlmfnebg",
  "writeKey": "***:***",
  "context": {
    "library": {
      "name": "@jitsu/js",
      "version": "0.0.0"
    },
    "traits": {},
    "page": {},
    "clientIds": {
      "ga4": {}
    },
    "campaign": {}
  }
}
Event 1 tracked
[JITSU EMPTY RUNTIME] Get storage item __user_id=undefined
[JITSU EMPTY RUNTIME] Get storage item __anon_id="69592ef2-1db7-4713-9f17-8d166aad014a"
[JITSU EMPTY RUNTIME] Get storage item __user_traits=undefined
[JITSU EMPTY RUNTIME] Get storage item __user_traits=undefined
[JITSU] http://jitsu-develop.d.in/api/s/track replied 200. Original payload:  {
  "type": "track",
  "event": "EVENT_2",
  "properties": {},
  "userId": null,
  "anonymousId": "69592ef2-1db7-4713-9f17-8d166aad014a",
  "timestamp": "2023-11-15T23:45:31.469Z",
  "sentAt": "2023-11-15T23:45:31.469Z",
  "messageId": "1ot6x6srs6b2gj3r7gngf8",
  "writeKey": "***:***",
  "context": {
    "library": {
      "name": "@jitsu/js",
      "version": "0.0.0"
    },
    "traits": {},
    "page": {},
    "clientIds": {
      "ga4": {}
    },
    "campaign": {}
  }
}
Event 2 tracked

Environment:

  • @jitsu/js Version: 1.7.1
  • Node.js Version: v18.17.1
@vklimontovich
Copy link
Contributor

This is fixed, please upgrade to 1.7.2

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