Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
Add analytics and cookie notice
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelPasvolsky committed Jun 3, 2019
1 parent 6bc906c commit 3fd9a51
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
31 changes: 31 additions & 0 deletions docs/_static/cookie_notice.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#cookie-notice {
display: none;
bottom: 0;
position: fixed;
width: 100%;
background: white;
z-index: 1000000;
height: auto;
text-align: center;
}
.cookie-button {
border: none;
display: inline-block;
justify-content: center;
height: 48px;
font-size: 16px;
font-weight: 600;
border-radius: 4px;
background: rgb(41, 128, 185);
box-shadow: 0 5px 14px 0 rgba(29,30,36,0.19);
color: #fff;
cursor: pointer;
padding-top: 12px;
padding-bottom: 12px;
padding-left: 42px;
padding-right: 42px;
margin: 1em;
margin-left: 2em;
white-space: nowrap;
vertical-align: middle;
}
29 changes: 29 additions & 0 deletions docs/_static/cookie_notice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const send_ga = () => {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-124167090-6', 'auto');
ga('send', 'pageview');
}

let cookieAccepted = localStorage.cookieAccepted;
if (cookieAccepted == undefined) {
$(document).ready(function () {
var cookieDiv = document.createElement('div')
cookieDiv.id = 'cookie-notice'
cookieDiv.innerHTML = "<p style='margin: 1em'>Privacy and Cookies: This site uses cookies. By continuing to use this website, you agree to their use. To find out more, see our <a style='color:#4c71c6; text-decoration: underline;' href='https://cloud.dwavesys.com/leap/legal/privacy_policy/' target='_blank'>Privacy Policy</a>.<button id='cookie-accept' class='cookie-button'>Close and Accept</button></p>"

$('body').append(cookieDiv).ready(() => {
$('#cookie-notice').fadeIn('slow');
$("#cookie-accept").click(function () {
localStorage.setItem("cookieAccepted", true)
$('#cookie-notice').fadeOut('slow');
send_ga()
});
})
})
} else if (cookieAccepted == "true") {
send_ga()
}
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
html_static_path = ['_static']

def setup(app):
app.add_stylesheet('cookie_notice.css')
app.add_javascript('cookie_notice.js')

# -- Options for HTMLHelp output ------------------------------------------

Expand Down

0 comments on commit 3fd9a51

Please sign in to comment.