Created
June 10, 2012 15:18
-
-
Save d6y/2906159 to your computer and use it in GitHub Desktop.
Example cookie notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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