# Data Collection API - User Id

**URL:** <https://community.piwik.pro/t/data-collection-api-user-id/4573>\
**Category:** Data collection and tags\
**Created:** [October 22, 2024, 11:24pm UTC](https://community.piwik.pro/t/data-collection-api-user-id/4573 "2024-10-22T23:24:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Optizent](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/optizent/32/475_2.png) [@Optizent](https://community.piwik.pro/u/Optizent)\
**Post date:** [October 22, 2024, 11:24pm UTC](https://community.piwik.pro/t/data-collection-api-user-id/4573/1 "2024-10-22T23:24:43Z")

</div>

When I user Data Tracking API for sending the data to Piwik PRO, how is the user id created? I am assume I will have send an id.  
The example value in documentation says, I need to send an ID like this \_id=257cc22df0ec483a. Do I need to send ID for both anonymous users and known users?

---

<div class="post-metadata">

**Author:** ![Adam](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/adam/32/1494_2.png) [@Adam](https://community.piwik.pro/u/Adam)\
**Post date:** [October 24, 2024, 11:18am UTC](https://community.piwik.pro/t/data-collection-api-user-id/4573/2 "2024-10-24T11:18:26Z")

</div>

Hi Anil,

In general in Piwik PRO as soon as we have value which should be assigned to User ID, we use it. Regardless of wether the consent is given or not. That said, even if consent was not given and you push our function an assign User ID it will be assigned later on to the specific session.

NOTE: Invoking `setUserId` won’t send any tracking request. To add User ID to tracked data, you have to call `setUserId` before [trackPageView](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#jtc-api-trackpageview). It does not have to be the first one. Another way is to send ping request with [ping](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#jtc-api-ping), after setting the User ID.
