# Collecting Session URL

**URL:** <https://community.hubspot.com/t/collecting-session-url/131265>\
**Category:** CMS Development\
**Tags:** enterprise\
**Created:** [May 8, 2025, 12:13pm UTC](https://community.hubspot.com/t/collecting-session-url/131265 "2025-05-08T12:13:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![omaklad](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@omaklad](https://community.hubspot.com/u/omaklad)\
**Post date:** [May 8, 2025, 12:13pm UTC](https://community.hubspot.com/t/collecting-session-url/131265/1 "2025-05-08T12:13:08Z")

</div>

Hello,

I have a chatbot created using chatflows on my website, I need to be able to capture a specific parameter from the session URL and save it to the contact record created by the bot.

I found a post talking about saving the param as a cookie in my website code then pass it to .\_hsq and if the variable matches a field on the contact proprety it should update it automatically, but it didn’t.

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [May 8, 2025, 5:53pm UTC](https://community.hubspot.com/t/collecting-session-url/131265/2 "2025-05-08T17:53:54Z")

</div>

Hey, @omaklad 👋 welcome to our community. Thanks for your post. I think our community members need additional information before they can help. Can you share:

- the post you are referring to
- code example(s) of how you implemented this on your end

Thank you! — Jaycee

---

<div class="post-metadata">

**Author:** ![omaklad](https://avatars.discourse-cdn.com/v4/letter/o/fbc32d/32.png) [@omaklad](https://community.hubspot.com/u/omaklad)\
**Post date:** [May 8, 2025, 6:34pm UTC](https://community.hubspot.com/t/collecting-session-url/131265/3 "2025-05-08T18:34:51Z")

</div>

Hi [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074)

I can’t find the exact post, but I basically

I put this code in my browser:  
first to create the cookie:

```lia-code-sample
<script>
 function getCookie(name) {
 var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
 return match ? decodeURIComponent(match[2]) : null;
 }

 var aid = getCookie('aid');

 if (aid && window._hsq) {
 console.log('%c[HubSpot AID] Success:', 'color: green; font-weight: bold;', 'Found aid =', aid, '| Sending to HubSpot via _hsq');
 window._hsq.push(['identify', {
 aid: aid
 }]);
 } else if (!aid) {
 console.warn('%c[HubSpot AID] Warning:', 'color: orange; font-weight: bold;', 'No aid value found in cookie.');
 } else if (!window._hsq) {
 console.error('%c[HubSpot AID] Error:', 'color: red; font-weight: bold;', 'HubSpot tracking object (_hsq) not found.');
 }
</script>

```

Then to get the cookie and send it to hsq:

```lia-code-sample
<script>
 function getCookie(name) {
 var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
 return match ? decodeURIComponent(match[2]) : null;
 }

 var aid = getCookie('aid');
 var maxAttempts = 10;
 var attempts = 0;

 var interval = setInterval(function () {
 if (typeof window._hsq !== 'undefined') {
 if (aid) {
 console.log('%c[HubSpot AID] Success:', 'color: green; font-weight: bold;', 'Found aid =', aid, '| Sending to HubSpot via _hsq');
 window._hsq.push(['identify', { aid: aid }]);
 } else {
 console.warn('%c[HubSpot AID] Warning:', 'color: orange; font-weight: bold;', 'No aid value found in cookie.');
 }
 clearInterval(interval);
 } else {
 attempts++;
 if (attempts >= maxAttempts) {
 console.error('%c[HubSpot AID] Error:', 'color: red; font-weight: bold;', 'HubSpot tracking object (_hsq) not found after 10 attempts.');
 clearInterval(interval);
 }
 }
 }, 500); // Check every 500ms
</script>

```

And assumed once the contact is created hubspot will be able to link that aid value to the customer contact field i created thats called aid too.
