microsoft / clarity

A behavioral analytics library that uses dom mutations and user interactions to generate aggregated insights.
https://clarity.microsoft.com
MIT License
2.14k stars 213 forks source link

Custom identify `user id` not being used #167

Open johnbacon opened 3 years ago

johnbacon commented 3 years ago

We've manually integrated Clarity in the <head> of our website. When a logged-in user is present, we use window.clarity('identify', '*'); to submit their numeric account ID as a string. Like this!

    <script>
        (function(c,l,a,r,i,t,y){
            c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
            t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
            y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
        })(window, document, "clarity", "script", "abcd1234");

                window.clarity('identify', '7654321'); // Example 7-digit ID as on the site
        window.clarity('set', 'Page Type', "Example");
        window.clarity('set', "Account ID", "7654321");
        window.clarity('set', "User Type", "Example");
    </script>

This custom identifier doesn't seem to be used on clarity.microsoft.com or searchable by the User ID filter. Instead, we see the auto-generated User IDs (like 8p6jh3).

What are we doing wrong here? Or does the feature not operate as we imagine?

We've attempted to work around this issue with the Account ID custom filter as you can see above, but because those filters cannot be copy + pasted and only seem to accept up to three characters, it makes it impractical for our purposes. (This particular use case is for support and engineering to better debug issues that happen.)

CC: @markb423 / @soundslocke

milannankov commented 3 years ago

I have got the same issue. I seem to be making the right calls but the user_id that I am providing is not being respected.

@johnbacon , at first I taught that consent might have been required for you to use "identify" but I am calling consent and user_id is still not respected.

I am using Clarity in a React app where the tracking code is loaded in "" and then I call consent and identify in one of my components. I am also trying to set some addition data that is needed in my context but it is not recorded as well. Here is the simplified version:

window.clarity('consent'); window.clarity("identify", "myuserid"); window.clarity("set", "domain", "mydomain");

What I have noticed looking at the source code of Clarity is that there is a check for "active()" - when false, operations like identify will not do anything. So I am wondering the call to identify is called a bit too early.

Any suggestions are welcome.

agtenr commented 2 years ago

We are encountering the same issue as well. We cannot get the identify property to work. This is a big issue for us because the distinct user count is way off. Any input from the clarity team would be greatly appreciated.

remy727 commented 2 years ago

Any updates on this?

noahsark769 commented 2 years ago

Also wondering if there's an update on this, looks like we're seeing the same thing

amit-feldman commented 2 years ago

+1

oeddyo commented 2 years ago

Is it possible someone from MS could take a look?

straxico commented 2 years ago

+1

subratamal commented 2 years ago

+1

yelianjie commented 2 years ago

+1

LeoTanoue commented 2 years ago

+1

ahendouz commented 2 years ago

Any updates?

SamPPCProtect commented 2 years ago

We've recently experienced this problem also, any updates?

ClaritySupport commented 2 years ago

@johnbacon ,Please use Custom user ID under Custom filters instead of user ID, Custom Tags in Clarity.

straxico commented 2 years ago

@johnbacon ,Please use Custom user ID under Custom filters instead of user ID, Custom Tags in Clarity.

A single page can have no more than 128 tags. Any other tags will be ignored.

johnbacon commented 2 years ago

@ClaritySupport – as @straxico mentioned, this is unfortunately not an acceptable solution.

Are you official Clarity support?

straxico commented 2 years ago

@ClaritySupport – as @straxico mentioned, this is unfortunately not an acceptable solution.

Are you official Clarity support?

no . i suggest to see posthog

ClaritySupport commented 2 years ago

@johnbacon, Yes we are official Clarity support. Sorry for the confusion. Any id that you sent us via identify API, you can enter it in the Custom user ID filter within the Custom filters section.

image

GFoley83 commented 1 year ago

Can anyone confirm that this solution worked for them?

@ClaritySupport if you are official support then you should really be a marked as a contributor to this repo. Otherwise it just looks really suspicious as your profile is blank with zero permissions.

@sarveshnagpal Can you confirm this please?

NegTakashiro commented 1 year ago

Any updates? Tried with and without "window." prefix, the set command worked without the prefix but no matter what I do or how I present the code, custom user id is never utilized. (Coming from Shopify with a mix of .liquid)

ClaritySupport commented 1 year ago

@NegTakashiro ,Could you please enter it in the Custom user ID filter within the Custom filters section.

image

santilorenzo commented 1 year ago

@NegTakashiro ,Could you please enter it in the Custom user ID filter within the Custom filters section.

image

I have this on my webpage: window.clarity('identify', 43)

But if I filter for that identifier, this is the result:

Schermata 2023-02-21 alle 17 28 56

I also tried window.clarity('set', 'myuserid', 43) but I can't see any custom tag dropdown select:

Schermata 2023-02-21 alle 17 30 31

NegTakashiro commented 1 year ago

@ClaritySupport I am using that field, and to add more context I'm using window.clarity('identify', {{shopify.parameter.here}}, {{another.shopify.parameter}})

Where the "another.shopify.parameter" sort of works and is searchable under custom session id, but the first custom user id field, is not working at all.

NegTakashiro commented 1 year ago

@NegTakashiro ,Could you please enter it in the Custom user ID filter within the Custom filters section. image

I have this on my webpage: window.clarity('identify', 43)

But if I filter for that identifier, this is the result:

Schermata 2023-02-21 alle 17 28 56

I also tried window.clarity('set', 'myuserid', 43) but I can't see any custom tag dropdown select:

Schermata 2023-02-21 alle 17 30 31

@santilorenzo Have you tried to make it a string? window.clarity('identify', '43')?

ClaritySupport commented 1 year ago

@NegTakashiro , please verify that the user id you're passing to Clarity is valid. Clarity requires that user ids be a string of no more than 255 characters. Additionally, Clarity will not accept user ids that contain certain characters, such as <, >, and &. If you're passing an invalid user id, Clarity may not be able to use it.

kepboy commented 1 year ago

I'm trying to get claritry to use my customer ID but when I call clarity("identify", "190-3213-321321") it returns a promise. Upon success that promise returns an object with two properties, userId and userHint. The userId is a large numeric that must be generated by Clarity. the userHint property contains the first two characters from my custom user Id followed by ***s, i.e. "19***********"

I also call clarity("set", "appUserId", "190-3213-321321") and it doesn't seem to do anything at all. No custom labels or tags show up in the clarity user interface.

Is this broken? a change and the documentation hasn't been updated? Help...

ClaritySupport commented 1 year ago

@kepboy ,Could you please share project iD.The documentation for the change in identity api will be updated soon.

You can still filter by entering value "190-3213-321321" in Custom User Id on the clarity website.

merobal commented 1 year ago

@ClaritySupport I have an interesting update: image

Our "Customised user ID" does appear. But when I click on it (so I set it as a filter) it does not show any results. image

We use Google Tag Manager, so we send the user_id as a string from today (we sent it as an integer in the past): image But I'm still experiencing the same issue as above.

Summary: Clarity is able to receive the user_id, but isn't able to use it as a filter.

Project id: fksiplvzvw

ayusshar commented 1 year ago

Facing similar issues. So I have two problems, First one is I have tried below code - window.clarity('set', 'DoctorID', DoctorID?.toString())

But no custom tags are appearing on my project.

Second one - When I am using - window.clarity('identify', DoctorID?.toString()) , Clarity is showing this on screen with added hash, so i am not able to make use of Custom User Id filter.

ClaritySupport commented 1 year ago

Hello,

Could you please share Clarity project ID and website address to investigate further.

Thanks, Clarity Support Team Visit our docs!: https://docs.microsoft.com/en-us/clarity @.**@.> @.***

Confidentiality note: This e-mail, and any attachment to it, contains privileged and confidential information intended only for the use of the individual(s) or entity named in the e-mail. If the reader of the e-mail is not the intended recipient, or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that reading it is strictly prohibited. If you have received this e-mail in error, please immediately return it to the sender and delete it from your system.

From: ayusshar @.> Sent: Friday, June 16, 2023 1:32 AM To: microsoft/clarity @.> Cc: Microsoft Clarity Support @.>; Mention @.> Subject: Re: [microsoft/clarity] Custom identify user id not being used (#167)

Facing similar issues. So I have two problems, First one is I have tried below code - window.clarity('set', 'DoctorID', DoctorID?.toString())

But no custom tags are appearing on my project.

Second one - When I am using - window.clarity('identify', DoctorID?.toString()) , Clarity is showing this on screen with added hash, so i am not able to make use of Custom User Id filter.

- Reply to this email directly, view it on GitHubhttps://github.com/microsoft/clarity/issues/167#issuecomment-1594317140, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AW5BXQZK6B3ZDZCGQQYYMITXLQKZDANCNFSM5C3OELLA. You are receiving this because you were mentioned.Message ID: @.**@.>>

ClaritySupport commented 1 year ago

Hello,

We are unable to repro it, see results here: Redmenta - Clarity (microsoft.com)https://clarity.microsoft.com/projects/view/fksiplvzvw/impressions?CustomUserId=is%3B204675456&date=Custom&end=1684997940000&start=1684738800000 when I filter to Custome User ID: 204675456

Thanks, Clarity Support Team Visit our docs!: https://docs.microsoft.com/en-us/clarity @.**@.> @.***

Confidentiality note: This e-mail, and any attachment to it, contains privileged and confidential information intended only for the use of the individual(s) or entity named in the e-mail. If the reader of the e-mail is not the intended recipient, or the employee or agent responsible for delivering it to the intended recipient, you are hereby notified that reading it is strictly prohibited. If you have received this e-mail in error, please immediately return it to the sender and delete it from your system.

From: Bálint @.> Sent: Tuesday, May 23, 2023 3:28 AM To: microsoft/clarity @.> Cc: Microsoft Clarity Support @.>; Mention @.> Subject: Re: [microsoft/clarity] Custom identify user id not being used (#167)

@ClaritySupporthttps://github.com/ClaritySupport I have an interesting update: [image]https://user-images.githubusercontent.com/5844511/240232496-1c1f16b4-6b73-431d-baa4-881c439d3c0c.png

Our "Customised user ID" does appear. But when I click on it (so I set it as a filter) it does not show any results. [image]https://user-images.githubusercontent.com/5844511/240232826-f996f037-d1a2-43af-b263-b91bcab1c1c2.png

We use Google Tag Manager, so we send the user_id as a string from today (we sent it as an integer in the past): [image]https://user-images.githubusercontent.com/5844511/240233813-f3e08a16-d029-42d5-9fc7-32789e2734fe.png But I'm still experiencing the same issue as above.

Summary: Clarity is able to receive the user_id, but isn't able to use it as a filter.

Project id: fksiplvzvw

- Reply to this email directly, view it on GitHubhttps://github.com/microsoft/clarity/issues/167#issuecomment-1559009243, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AW5BXQ6GMCGYAFJKDM7L2U3XHSGK7ANCNFSM5C3OELLA. You are receiving this because you were mentioned.Message ID: @.**@.>>

thedevvikas commented 1 year ago

Hi, I am also facing the same issue. Our custom uids appear momentarily in recordings tab as Customised User ID then disappears. Also, in filters modal, no custom tags are visible...though we are setting custom tags using window.clarity("set", customTag)

marianaesteban commented 1 year ago

Any updates on this? I'm experiencing the same issue. When sending the user's email as a customID, I'm not finding the sessions using the Custom user ID filter

ayusshar commented 1 year ago

@ClaritySupport My issue is fixed now. RCA - There were two issues. First one - There were two clarity setup on my website. Thats why sometimes user id was appearing sometimes not. Second one - I was sending numeric id in 'set' API.

@marianaesteban @thedevvikas Please check if your issues can be related to above issues.

kushal-ground0 commented 1 year ago

Able to set the custom user id, but it's getting encrypted and being set?

Screenshot 2023-09-13 at 11 41 09 AM

ClaritySupport commented 1 year ago

@kushal-ground0 ,Clarity securely hashes the custom-id on the client before being sent to Clarity servers. For an optimal user tracking, the Identify API should be called for each page of the website even though you are not passing a custom-session-id or custom-page-id. Identify API | Microsoft Learn

kushal-ground0 commented 1 year ago

Our usecase is to view clarity sessions with respect to the custom id from our db, will i have to store those encrypted id in db from identify result?

ClaritySupport commented 1 year ago

@kushal-ground0 , Please refer Identify API | Microsoft Learn ,you can log identifiers with that API and search for them. We store them hashed so we never have the real value.

Ahl-am commented 11 months ago

I used an email just like in the documentation, and it still doesn't filter when I search for the users. I don't understand exactly what is missing. this is sent from every page:

window.clarity("identify", userEmail)
ClaritySupport commented 11 months ago

@Ahl-am , user email should be in double quotes, window.clarity("identify","useremail"), for more details please refer https://learn.microsoft.com/en-us/clarity/setup-and-installation/identify-api

snyaggarwal commented 10 months ago

@ClaritySupport I am stuck with this problem as well. I have gone through this thread and tried out possible suggestions, but couldn't get the desired result. Let me try to explain whats working and whats not: Our process from React app:

clarity('consent');
clarity("identify", `"${user.email}"`)
clarity('set', 'userId', user.username)
  1. We can see the recordings and it has our user.username in the "Custom user ID" field against the recording. This works as expected
  2. "User ID" has a randomly generated ID. We tried sending str(user.id) or user.username or hardcoded content base 36 string. Nothing reflects on Clarity except random generated ID.

We tried a similar approach with Android SDK and 2nd point above works there, passing our user ID reflecting in Clarity. This is only a web js issue.

Any help/direction would be highly appreciated.

italoiz commented 10 months ago

I was able to use Custom user ID, but after some tests, I realized that the filter on the dashboard only works after about 2 hours. I'm using Google Tag Manager to load clarity into my platform, and when users sign in to your account, I'm triggering the API to identify the user.

// clarity.ts
export const identifyClarityUser = (userId: string) => {
  const isApiAvailable = typeof window?.clarity === "function";

  if (!isApiAvailable)
    return;

  window.clarity("identify", userId);
};

//After the user signs in just call the identifyClarityUser
identifyClarityUser('b4577d05-b854-481c-8879-0805dae71031');

You can also use the Custom Tags to try to identify the users. Here is a similar implementation using the custom tags.

// clarity.ts
export const identifyClarityUser = (userId: string) => {
  const isApiAvailable = typeof window?.clarity === "function";

  if (!isApiAvailable)
    return;

  window.clarity("set", "user_id", userId);
};

//After the user signs in just call the identifyClarityUser
identifyClarityUser('b4577d05-b854-481c-8879-0805dae71031');

But keep in mind that the data might take some time to get available on the dashboard and it's good to wait at least 2 hours to try to see the data on there.

References

https://learn.microsoft.com/en-us/clarity/setup-and-installation/clarity-api https://learn.microsoft.com/en-us/clarity/setup-and-installation/identify-api

nik32 commented 10 months ago

@italoiz If I understand clarity support's reply here correctly... then the user_id will be lost on page refresh. So calling identifyClarityUser, just after user signs in, might lead to session not being tracked, isn't it??

italoiz commented 9 months ago

@italoiz If I understand clarity support's reply here correctly... then the user_id will be lost on page refresh. So calling identifyClarityUser, just after user signs in, might lead to session not being tracked, isn't it??

@nik32 I'm using NextJS as the application, and I use the same strategy when the user refreshes the page to set the user ID; it seems to be working pretty well.

nik32 commented 9 months ago

@italoiz Thanks for the reply! Just to confirm... you are setting the userId only once when the user signs in (and not on every page reload)!

italoiz commented 9 months ago

@nik32 I'm also setting the user id when the user reloads the page after I get the user session.

dutta-roy-samrat commented 8 months ago

@ClaritySupport why is that my promise returns everything correctly, but on clarity I don't seem to find the custom user id and custom session id filters in recording

kabdelkareem commented 5 months ago

same issue here that nothing appear in Clarity whatever I do

Alerinos commented 5 months ago

@ClaritySupport i have the same problem:

    @if (Authenticated.User is not null)
    {
        <script type="text/javascript">
            (function (c, l, a, r, i, t, y) {
                c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
                t = l.createElement(r); t.async = 1; t.src = "https://www.clarity.ms/tag/" + i;
                y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);

                t.onload = function () {
                    window.clarity('consent');
                    window.clarity("set", "userId", "@Authenticated.User.Id");
                    window.clarity("set", "userName", "@Authenticated.User.Name");
                    window.clarity("identify", "@Authenticated.User.Id", null, null, "@Authenticated.User.Name");
                };

            })(window, document, "clarity", "script", "xxx");
        </script>
    }

What am i doing wrong?

pashamed commented 5 months ago

window.clarity("identify", userId); works. Microsoft docs says, userId value is hashed and wont be visible to you in dashboard, instead it will be randomly generated tag. BUT, if you filter by the value that you provided to userId, it will find it, Clarity will hash the value and compare it to the value in DB. Probably done for legislation concerns.

Clarity doesn't store custom identifier as a plain text. Instead, the custom ID is hashed on the client before being sent to the servers. When you filter on a specific Custom user ID, Clarity hashes the input and matches it against the data to retrieve the right sessions.