# How can I tell the PiwikPro to set Cookie Expire to 30 days programmatically

**URL:** https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709
**Category:** Privacy
**Created:** [February 28, 2024, 7:06am UTC](https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709 "2024-02-28T07:06:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kishorth](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kishorth/32/3151_2.png) [@kishorth](https://community.piwik.pro/u/kishorth)
#### Post date: [February 28, 2024, 7:06am UTC](https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709/1 "2024-02-28T07:06:36Z")

</div>

Hello support,

How can I tell the PiwikPro to set Cookie Expires/ Max-Age to 30 days instead of 12 months programmatically? I am not using Tag Manager and I am deploying on my own.

This is the code I use

```auto
var _paq = _paq || [];
_paq.push(["trackPageView"]),
  _paq.push(["enableLinkTracking"]),  
  (function () {
    var e = "https://foxscribbler.piwik.pro/";
    _paq.push(["setTrackerUrl", e + "ppms.php"]),
    _paq.push(["setSiteId", "0d96a69e-f206-4b60-9a02-de57294b7f06"]);
  
    var p = document,
      a = p.createElement("script"),
      r = p.getElementsByTagName("script")[0];
    (a.type = "text/javascript"),
      (a.async = !0),
      (a.defer = !0),
      (a.src = e + "ppms.js"),
      r.parentNode.insertBefore(a, r);
  })();

```

This is the [result](https://piwik.pro/cookie-scanner-report/?url=https%3A%2F%2Ffoxscribbler.com%2Fvertical-scroll-snap-anchor-links-no-js%2F)

---

<div class="post-metadata">

### Author: ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)
#### Post date: [February 28, 2024, 7:11am UTC](https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709/2 "2024-02-28T07:11:38Z")

</div>

Hi @kishorth,

Try using this:

```auto
_paq.push(['setVisitorCookieTimeout', 2592000]);

```

> **[API](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#setVisitorCookieTimeout)**
>
> The following API allows the user to: track page views, track visits on multiple domains and subdomains, track e-commerce events (successful orders, cart changes, product and category views), track...

---

<div class="post-metadata">

### Author: ![kishorth](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kishorth/32/3151_2.png) [@kishorth](https://community.piwik.pro/u/kishorth)
#### Post date: [February 29, 2024, 6:20am UTC](https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709/3 "2024-02-29T06:20:20Z")

</div>

So is my syntax correct?

```auto
var _paq = _paq || [];
  _paq.push(["trackPageView"]),
  _paq.push(["enableLinkTracking"]),
  _paq.push(["setVisitorCookieTimeout", 2592000]);
(function () {
  var e = "https://foxscribbler.piwik.pro/";
  _paq.push(["setTrackerUrl", e + "ppms.php"]),
    _paq.push(["setSiteId", "0d96a69e-f206-4b60-9a02-de57294b7f06"]);

  var p = document,
    a = p.createElement("script"),
    r = p.getElementsByTagName("script")[0];
  (a.type = "text/javascript"),
    (a.async = !0),
    (a.defer = !0),
    (a.src = e + "ppms.js"),
    r.parentNode.insertBefore(a, r);
})();

```

---

<div class="post-metadata">

### Author: ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)
#### Post date: [February 29, 2024, 7:47am UTC](https://community.piwik.pro/t/how-can-i-tell-the-piwikpro-to-set-cookie-expire-to-30-days-programmatically/3709/4 "2024-02-29T07:47:10Z")

</div>

Looks fine to me. It’s worth mentioning that if you previously called `disableCookies` then you should call `enableCookies` before setting the cookie lifetime.
