Merge branch 'feature/user_domain_tracking' into 'master'

Set a custom variable in piwik in order to track the authenticated user's origin/domain

Closes #146

See merge request cara/cara!153
This commit is contained in:
Nicola Tarocco 2021-03-26 10:28:09 +00:00
commit c87ec4f4cb
3 changed files with 22 additions and 1 deletions

View file

@ -12,6 +12,10 @@ class User:
"""Return True if current user is not authenticated."""
raise NotImplementedError
def domain(self) -> str:
"""Return a domain for this user. The domain must not be specific enough to identify a single user."""
return 'other'
@dataclass
class AuthenticatedUser(User):
@ -25,9 +29,16 @@ class AuthenticatedUser(User):
def is_anonymous(self) -> bool:
return False
def domain(self) -> str:
if self.email.lower() == "cara.un@cern.ch" or self.email.endswith('@un.org'):
return 'UN.org'
elif self.email.lower().endswith('@cern.ch'):
return 'CERN'
else:
return 'other'
class AnonymousUser(User):
def is_authenticated(self) -> bool:
return False

View file

@ -1,5 +1,8 @@
if (document.location.hostname == "test-cara.web.cern.ch") {
var _paq = _paq || [];
if (typeof AuthUserDomain !== 'undefined') {
_paq.push(["setCustomVariable", 1, "AuthUserDomain", AuthUserDomain, "visit"]);
}
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {
@ -17,6 +20,10 @@ if (document.location.hostname == "test-cara.web.cern.ch") {
})();
} else if (document.location.hostname == "cara.web.cern.ch") {
var _paq = _paq || [];
if (typeof AuthUserDomain !== 'undefined') {
_paq.push(["setCustomVariable", 1, "AuthUserDomain", AuthUserDomain, "visit"]);
}
_paq.push(["setCustomVariable", 1, "AuthUserDomain", AuthUserDomain, "visit"]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function () {

View file

@ -77,6 +77,9 @@
// Disabled until we tidy up the CSS... ;)
<li><a href="/auth/logout">Sign out</a></li>
-->
<script>
var AuthUserDomain = "{{ user.domain() }}";
</script>
{% endif %}
<li><a href="https://cern.ch/directory" class="cern-directory ext"title="Search CERN resources and browse the directory" data-extlink="">Directory</a></li>
</ul>