Skip to content

Instantly share code, notes, and snippets.

@d6y
Created June 10, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d6y/2906159 to your computer and use it in GitHub Desktop.
Save d6y/2906159 to your computer and use it in GitHub Desktop.
Example cookie notification
import bootstrap.liftmodules.GoogleAnalytics
import GoogleAnalytics.dsl._
// Always track
GoogleAnalytics.init
// Provide a one-time banner, based on the absence of a cookie:
GoogleAnalytics.alertUser( only when( S.cookieValue("ckns_policy").isEmpty ) {
import net.liftweb.http.js._
import JE._
import JsCmds._
import net.liftweb.http.provider.HTTPCookie
// Set the cookie to prevent showing this page again:
val oneYear = 365 * 24 * 60 * 60
S.addCookie( HTTPCookie("ckns_policy", "1").setPath("/").setMaxAge(oneYear) )
// Add a div to the top of the page with some information in it:
JsRaw("$('body').prepend('<div id=notice></div>')") &
SetHtml("notice", <div>
<div id="title">Cookies on our website</div>
<div id="info">We use cookies to ensure that we give you the best experience on our website.
If you continue without changing your settings, we'll assume that you are
happy to receive all cookies on the our website.
<a href="/cookies.html">Find out more</a> about our cookie policies. </div>
</div>)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment