Jump to content

Recommended Posts

Posted

Hey.

What would be a clever way of detecting if the page being rendered is the first viewed in a session?

Think landing page. In fact, think blog article. I want to put a CTA there that would appear only if the user just landed directly in that page. But if the user came from, i.e., the homepage, I want it to behave differently.

Any ideas?

 

Thanks,
H

Posted
if(!$session->get('flag'){
	echo 'New visitor';
	$session->set('flag');
} else {
	echo 'Been here a while';
}

Completely untested but can't think why it shouldn't work.

  • Like 1
  • Thanks 1
Posted

A user going directly to a page is either from a bookmark or typing (pasted) url. So you could check both the referrer and bookmarks on the desired target page(s). Otherwise you'd have to test and set a result (as @DaveP shows) on all non-target pages, then test for that result on all target pages.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...