# Detect whether page visitor is new or returning

**URL:** <https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852>\
**Category:** CMS Development\
**Tags:** professional\
**Created:** [May 6, 2021, 3:39pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852 "2021-05-06T15:39:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JLiles](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jliles/32/14279_2.png) [@JLiles](https://community.hubspot.com/u/JLiles)\
**Post date:** [May 6, 2021, 3:39pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/1 "2021-05-06T15:39:24Z")

</div>

Is there a simple way to detecth whether a page visitor is new or returning in HubSpot CMS? I would like to display different content depending on whether they are new or returning, regardless of whether they have filled out a form and become a contact.

Ideally, it would be a smart content option, but it doesn’t look like it is supported there. Less ideally, I would like to use some combination of JavaScript and HubL to use (set, if necessary) cookies.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [May 7, 2021, 3:26pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/2 "2021-05-07T15:26:39Z")

</div>

@JLiles

How does smart content not work for this situation?

@jonchim , @piersg any thoughts here?

---

<div class="post-metadata">

**Author:** ![JLiles](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jliles/32/14279_2.png) [@JLiles](https://community.hubspot.com/u/JLiles)\
**Post date:** [May 7, 2021, 3:37pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/3 "2021-05-07T15:37:43Z")

</div>

Hi Dennis,

I may be misunderstanding Smart Content, but I thought it was based on either contact information or “anonymous” information like device type. I want to display different content based on whether a user has visited the page before, regardless of whether they are a contact. But perhaps I am missing an option or trick.

 ![JLiles_0-1620401566705.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/7/73d1a4eab295434763eec1e67e74ad74e88c6118.png)

---

<div class="post-metadata">

**Author:** ![jonchim](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jonchim/32/88818_2.png) [@jonchim](https://community.hubspot.com/u/jonchim)\
**Post date:** [May 7, 2021, 3:37pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/4 "2021-05-07T15:37:33Z")

</div>

For existing contacts, using smart content would definitely work. But I guess there’s no way to determine if a visitor is a return visitor if they’re not already a contact. 🤔Not sure there’s an easy solution without having to use javascript, etc. Let me see if I can find any solutions.

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [May 7, 2021, 4:11pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/5 "2021-05-07T16:11:31Z")

</div>

I think @jonchim is correct. Smart content will work for testing new/existing contacts but to determine if a visitor is new or returning you would have to use JS: for example, by testing if the hubspotutk cookie has been set (which is an id given to a visitor after they’ve accepted cookies on your site).

```lia-code-sample
function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0, len = ca.length; i < len; i++) {
 var c = ca[i];
 while (c.charAt(0)==' ') c = c.substring(1,c.length);
 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}
var hutk = readCookie('hubspotutk');
if (hutk != null || hutk != undefined) {
 // do things
}

```

---

<div class="post-metadata">

**Author:** ![JLiles](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jliles/32/14279_2.png) [@JLiles](https://community.hubspot.com/u/JLiles)\
**Post date:** [May 7, 2021, 4:14pm UTC](https://community.hubspot.com/t/detect-whether-page-visitor-is-new-or-returning/36852/6 "2021-05-07T16:14:26Z")

</div>

Great, thank you @piersg, @jonchim, and @dennisedson. That is along the lines of what I was thinking, but I just wanted to make sure there wasn’t a simpler solution that I was unaware of. I appreciate the prompt, respectful, and ultimately helpful assistance!
