AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Optimize
5.5K members online now
5.5K members online now
Discover how to select who is eligible to be in your experiment, and when they’re served experiment variations.
Guide Me
star_border
Reply

How can I have a test show on the first page in a session regardless of URL

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I want to test a certain experience for all landing pages, regardless of URL, so long as it is the first page in a users session. For example, I want have the internal search box exposed on mobile devices but only for the first page the visitor hits in that session. If I direct entry ford.com it will expose internal search on the homepage but subsequent pages. If I google "Ford F-150" and get taken to the landing page for the F-150 truck the internal search is exposed on that page but no subsequent pages.

 

Possible?

1 Expert replyverified_user

Re: How can I have a test show on the first page in a session regardless of URL

Google Employee
# 2
Google Employee
I think that you will need to do some work on your side for something like this.

One approach that I could think is to use a cookie to help you identify when a new session starts.
For example you could add some javascript in your site to store the last visit time of every visitor in a cookie.
Depending on your site, you can do this when the page loads (if your page is static) or as the visitor interacts (if your site has app features).

For example:
document.cookie = 'lastVisit='+(new Date().getTime());

(See https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie)

Now you can create a new "Custom javascript" variable in the targeting area, to return if the visit is the first visit of the session. You can use the GA rules for this or even come up with your own - for example, first visit after 90 minutes of inactivity.

Custom javascript variable: "First Session Visit"
function() {
var lastVisit = document.cookie.replace(/(?Smiley Sad?:^|.*;\s*)test2\s*\=\s*([^;]*).*$)|^.*$/, "$1");
var currentTime = (new Date().getTime());
var difference = currentTime - lastVisit
return difference > 90 * 60 * 1000; // 90 minutes in milliseconds
}

You will need some developer help with the above, I haven't tested the code and it may have bugs.

Once you have setup all the above, you can change the targeting of your experiment accordingly:
URL regexp .*
"First Session Visit" equals true

Hope that this helped.