# Access session information within Piwik PRO Tag Manager

**URL:** <https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866>\
**Category:** Data collection and tags\
**Created:** [February 3, 2025, 12:07pm UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866 "2025-02-03T12:07:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joao](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/joao/32/1820_2.png) [@joao](https://community.piwik.pro/u/joao)\
**Post date:** [February 3, 2025, 12:07pm UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866/1 "2025-02-03T12:07:01Z")

</div>

Hi everyone,

This is probably a stupid question, but is there any way to access session information (like Session number, Channel, Source) within Piwik PRO Tag Manager, like you can with Piwik PRO API?

The idea would be to send this information to third-party services as custom variables, for example for segmentation or filtering purposes.

Is this at all possible? 🤔

Thank you!

---

<div class="post-metadata">

**Author:** ![kamilb](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kamilb/32/309_2.png) [@kamilb](https://community.piwik.pro/u/kamilb)\
**Post date:** [February 4, 2025, 6:15pm UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866/2 "2025-02-04T18:15:46Z")

</div>

Hi @joao,

When it comes to the session number, you can get it using this method -

> **[getVisitorInfo](https://developers.piwik.pro/docs/getvisitorinfo)**
>
> The getVisitorInfo() method returns information about the visitor. Syntax getVisitorInfo() getVisitorInfo(): Promise getVisitorInfo(): Promise getVisitorInfo(): Promise getVisitorInfo(): Promise getVisitorInfo(): Promise\<...

“Previous visit count” could be used but please keep in mind that visitors can clear cookies and in this case you won’t have this information

When it comes to Channel / Source you would need to write some custom logic to get these values.

Have a great day! 🙂

---

<div class="post-metadata">

**Author:** ![joao](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/joao/32/1820_2.png) [@joao](https://community.piwik.pro/u/joao)\
**Post date:** [February 5, 2025, 8:21am UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866/3 "2025-02-05T08:21:57Z")

</div>

Hi @kamilb,

Thank you so much for your reply, I was unaware of that `getVisitorInfo()` method: this contains quite a lot of useful information that I can use for user segmentation (new users, returning users, past purchasers, etc.).

I know this information is dependent on the browser cookies, but given that the third-party integration doesn’t offer any user-scoped dimensions, this is already a great start!

For the channels I can always use UTM parameters in the URL and build some categories around those values. It would be nice if we could simply send whatever value Piwik PRO automatically assignes to the session, but I guess that’s wishful thinking.

Thank you again, much appreciated!

---

<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:** [February 12, 2025, 6:51am UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866/4 "2025-02-12T06:51:13Z")

</div>

I was also looking for this information. So how does this work?  
I create a custom JS variable and use something like this?

function() {

return getVisitorInfo());

}

That did not work for me.

Also, how can I use it in Google Tag Manager?

---

<div class="post-metadata">

**Author:** ![joao](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/joao/32/1820_2.png) [@joao](https://community.piwik.pro/u/joao)\
**Post date:** [February 12, 2025, 12:04pm UTC](https://community.piwik.pro/t/access-session-information-within-piwik-pro-tag-manager/4866/5 "2025-02-12T12:04:54Z")

</div>

Hi Anil,

There might be other (more recommended) ways to do this, but you can for example create a Custom HTML tag that creates a data layer push event with this information.

For example, something like:

```auto
<script>
  var _paq = _paq || [];
  _paq.push([function() {
    var visitorInfo = this.getVisitorInfo();
    var visitorId = visitorInfo ? visitorInfo[1] : undefined;
    window.dataLayer.push({
      event: 'user_info',
      visitorId: visitorId
    });
  }]);
</script>

```

You can then create data layer variables that retrieve the different visitor information from this custom event.
