# cookieID value as a variable

**URL:** <https://community.piwik.pro/t/cookieid-value-as-a-variable/2339>\
**Category:** Data collection and tags\
**Created:** [June 7, 2023, 8:21am UTC](https://community.piwik.pro/t/cookieid-value-as-a-variable/2339 "2023-06-07T08:21:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seo](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@seo](https://community.piwik.pro/u/seo)\
**Post date:** [June 7, 2023, 8:21am UTC](https://community.piwik.pro/t/cookieid-value-as-a-variable/2339/1 "2023-06-07T08:21:45Z")

</div>

Hi,

Can I use the cookieID value as a variable in the Piwik tag manager?  
If yes, how can I do that?  
(I would like to send this value to Microsoft Clarity later on)

Thanks

---

<div class="post-metadata">

**Author:** ![Admin](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@Admin](https://community.piwik.pro/u/Admin)\
**Post date:** [June 7, 2023, 9:01am UTC](https://community.piwik.pro/t/cookieid-value-as-a-variable/2339/2 "2023-06-07T09:01:11Z")

</div>

Hi. Something like that should work assuming that the analytics tracking library is already loaded.

```auto
function() {

  var visitorID;
  var _paq = window._paq || [];
  _paq.push([function() {visitorID = this.getVisitorId()}]);

  return visitorID;
}

```

You might need to delay sending the event to Clarity a bit to make sure that the `getVisitorID` method is already available.

Other solution would be to simply manually extract it from the `_pk_id` cookie. Cookies docs are available here: [Cookies created for visitors by Piwik PRO | Data and cookies | Piwik PRO help center](https://help.piwik.pro/support/privacy/cookies-created-for-visitors-by-piwik-pro/)
