# Extend pk\_id cookie with sever side gtm

**URL:** https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256
**Category:** Data collection and tags
**Created:** [November 17, 2023, 12:09pm UTC](https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256 "2023-11-17T12:09:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dandan](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dandan](https://community.piwik.pro/u/dandan)
#### Post date: [November 17, 2023, 12:09pm UTC](https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256/1 "2023-11-17T12:09:50Z")

</div>

Hi,

Would like to get your thoughts on this. I’d like to prolong the life of the pk\_id cookie.

And do so using the cookie monster tag in Google tag manager server side we can store the pk\_id cookie value in a custom created server side cookie. Lets call it the “backup cookie”. We can then overwrite the real pk\_id cookie using the cookie monster tag and the backup cookie value if the value in the real pk\_id doesnt exist or isn’t correct.

What do you think? would it be possible? does the pk\_id name or value change over time somehow?

---

<div class="post-metadata">

### Author: ![Oliwer\_Kaczmarek](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/oliwer_kaczmarek/32/3888_2.png) [@Oliwer\_Kaczmarek](https://community.piwik.pro/u/Oliwer_Kaczmarek)
#### Post date: [November 17, 2023, 2:26pm UTC](https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256/2 "2023-11-17T14:26:53Z")

</div>

Hi @dandan,

Here is a link to our documentation on pk\_id: [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/#cookie-details)  
And value does in fact change over time, for example with each visit the **visitsCount** goes up in the cookie. Those parts of the value change dynamically as well: **currentVisitTimestamp** , **lastVisitTimestamp** , **lastEcommerceOrderTimestamp**. So if you’d like to create a cookie to store this data as a backup make sure to update the value each time.

---

<div class="post-metadata">

### Author: ![mbaersch](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mbaersch/32/35_2.png) [@mbaersch](https://community.piwik.pro/u/mbaersch)
#### Post date: [November 17, 2023, 10:50pm UTC](https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256/3 "2023-11-17T22:50:28Z")

</div>

why do you want to create a copy instead of renewing the existing cookie every time a response is sent?

If you do not set the httpOnly flag, it will remain visible in the browser. Regarding ITP and other tracking protections rewriting cookies in a HTTP header will do the job without this flag.

best,  
Markus

---

<div class="post-metadata">

### Author: ![dandan](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dandan](https://community.piwik.pro/u/dandan)
#### Post date: [November 20, 2023, 8:52am UTC](https://community.piwik.pro/t/extend-pk-id-cookie-with-sever-side-gtm/3256/4 "2023-11-20T08:52:07Z")

</div>

> [@mbaersch](#):
>
> why do you want to create a copy instead of renewing the existing cookie every time a response is sent?
> 
> If you do not set the httpOnly flag, it will remain visible in the browser. Regarding ITP and other tracking protections rewriting cookies in a HTTP header will do the job without this flag.

Thanks Marcus! A bit n00b on this still. Will look further into this!
