CMS Development

JLiles
参加者

Detect whether page visitor is new or returning

解決

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.

0 いいね!
1件の承認済みベストアンサー
piersg
解決策
キーアドバイザー

Detect whether page visitor is new or returning

解決

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).

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
}

 

元の投稿で解決策を見る

5件の返信
JLiles
参加者

Detect whether page visitor is new or returning

解決

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!

jonchim
ガイド役 | Diamond Partner
ガイド役 | Diamond Partner

Detect whether page visitor is new or returning

解決

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.






Jon Chim
VP of Design & Development
Hypha HubSpot Development


check Did my post help answer your query? Help the Community by marking it as a solution
piersg
解決策
キーアドバイザー

Detect whether page visitor is new or returning

解決

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).

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
}

 

dennisedson
HubSpot製品開発チーム
HubSpot製品開発チーム

Detect whether page visitor is new or returning

解決

@JLiles 

How does smart content not work for this situation?

@jonchim , @piersg  any thoughts here?

0 いいね!
JLiles
参加者

Detect whether page visitor is new or returning

解決

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

 

0 いいね!