2

Client Side segment snippet sets ajs_user_id to null

Hi,

I'm trying to do an identify() on my server side and have it be respected by the client side segment snippets on the other sites on my domain. Currently my identify() on the server seems to work as expected and sets the ajs_user_id cookie to the userId that I pass into the call.

The problem arises when I navigate to any other site on the same domain (the cookie is valid on this domain) which has client-side segment snippet instead of on the server side set up. The snippet seems to set the ajs_user_id cookie to be `null` and then any calls to segment that are made become calls from an anonymous user with the user_id field being null. 

Not sure if I'm doing anything wrong here, I've got the same API key set up on both the sites and I've seen that until that client side script is run, the ajs_user_id cookie has the actual userId that I require to be passed into the subsequent calls. What should I be doing to make this work as expected?

4replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi Vishal,

    How are you currently sending the userId from your server to the client?
    Best,
    Xavier

    Reply Upvote
  • Hi Xavier,

    I just figured it out, looks like segment expects the ajs_user_id cookie to have a %22 (URL encoded double quotes) on either side of the id otherwise it thinks its a malformed cookie and resets it to null. I added " on either side while setting the cookie on my server side and things are working now.

    Reply Upvote
  • Glad to hear you were able to resolve the issue!

    Reply Upvote
  • Hi Vishal, Xavier

    We are able to set ajs_user_id to %22 url encoded value. Now, we want to make these anonymity cookies as secure. Could you please help us with a way to set secure flag on the above cookies.

    Thanks in advance.

    Reply Upvote