1

I am currently working on a task where for example an user visits www.site.com satisfying a particular condition I am supposed to make some visual transformations in the page. But this should only happen for the first time the user is shown the page. Subsequently if the user ignores the call to action and browses the site everything is normal.

To make sure that for a given session this transformation only happens once I am using document.referrer to check if it is 1. an "" string which means user might have entered the www.site.com address directly

  1. !document.referrer.match(/www.site.com/gi); - to make sure that the user is not referred from the internal pages back again to the home page.

This works in most cases except when user gets into the check funnel the url changes to a secure one https:// and when he is referred back to site.com home page the document.referrer returns an empty string which confuses my logic a the user is entering the address in the URL

Is there any other reliable way to solve this problem. Any help is much appreciated and thank you for taking time to read my problem

pnuts
  • 58,317
  • 11
  • 87
  • 139
Anand
  • 121
  • 3
  • 12
  • duplicate ? http://stackoverflow.com/questions/6023941/how-reliable-is-http-referer – Marged Nov 10 '15 at 22:10
  • I appreciate your quick reply . But my your link still does not give me a solution. I know that this approach is not reliable as i have mentioned. Do let me know if you have an alternative to my problem. – Anand Nov 10 '15 at 22:14
  • Why not just set a cookie that signals he already was presented with the content you only want to show him once ? – Marged Nov 10 '15 at 22:16
  • Honestly, after typing a reply to your earlier comment i was thinking the same but then if the user again enters the website address into the browser then cookie is already set which would prevent the desired transformation. But may be I can set cookie expiry with some reasonable time limit. But even still i am not sure if this is a reliable way to tackle this issue. Thank you responding. – Anand Nov 10 '15 at 22:19
  • Depending on how your page is implemented you can store "state" of your transformation in a global javascript variable. Or add an additional URL parameter, but this could cause problems when users bookmark the URL – Marged Nov 10 '15 at 22:23
  • Hi I have found a work around as the I do not have access to the website code due to client restrictions. I have dropped a session cookie once the transformation happens so that for that session irrespective of the protocol and when user internally browses other pages and returns to home page i always check the session cookie before executing transformation function. Hope this helps someone in the future. – Anand Nov 13 '15 at 13:25
  • I suggest you create an answer to your own question, including a code example. This might bring you at least +10 reputation ;-) – Marged Nov 13 '15 at 13:37

1 Answers1

0
function transformation(){
 // transformation code
}

 if(document.cookie.match(/someCookieName/) && document.location.href.match(/transformationPageURL/)){
  // call the transformation
     transformation();
    // set session cookie 
   document.cookie="someCookieName=true;";
  }else{
    // not the url to perform transformation or the cookie is already set which means its the same session.

// but still if the user again enters the same home page url the transformation //would not appear due to the cookie being set. But the changes of normal user //visiting the website and again entering the url of home page might be less }

Anand
  • 121
  • 3
  • 12