Set a custom variable in piwik in order to track the authenticated user's origin/domain.
This commit is contained in:
parent
d5d583ad8b
commit
71deccf6e0
3 changed files with 22 additions and 1 deletions
|
|
@ -12,6 +12,10 @@ class User:
|
||||||
"""Return True if current user is not authenticated."""
|
"""Return True if current user is not authenticated."""
|
||||||
raise NotImplementedError
|
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
|
@dataclass
|
||||||
class AuthenticatedUser(User):
|
class AuthenticatedUser(User):
|
||||||
|
|
@ -25,9 +29,16 @@ class AuthenticatedUser(User):
|
||||||
def is_anonymous(self) -> bool:
|
def is_anonymous(self) -> bool:
|
||||||
return False
|
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):
|
class AnonymousUser(User):
|
||||||
|
|
||||||
def is_authenticated(self) -> bool:
|
def is_authenticated(self) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
if (document.location.hostname == "test-cara.web.cern.ch") {
|
if (document.location.hostname == "test-cara.web.cern.ch") {
|
||||||
var _paq = _paq || [];
|
var _paq = _paq || [];
|
||||||
|
if (typeof AuthUserDomain !== 'undefined') {
|
||||||
|
_paq.push(["setCustomVariable", 1, "AuthUserDomain", AuthUserDomain, "visit"]);
|
||||||
|
}
|
||||||
_paq.push(["trackPageView"]);
|
_paq.push(["trackPageView"]);
|
||||||
_paq.push(["enableLinkTracking"]);
|
_paq.push(["enableLinkTracking"]);
|
||||||
(function () {
|
(function () {
|
||||||
|
|
@ -17,6 +20,10 @@ if (document.location.hostname == "test-cara.web.cern.ch") {
|
||||||
})();
|
})();
|
||||||
} else if (document.location.hostname == "cara.web.cern.ch") {
|
} else if (document.location.hostname == "cara.web.cern.ch") {
|
||||||
var _paq = _paq || [];
|
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(["trackPageView"]);
|
||||||
_paq.push(["enableLinkTracking"]);
|
_paq.push(["enableLinkTracking"]);
|
||||||
(function () {
|
(function () {
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,9 @@
|
||||||
// Disabled until we tidy up the CSS... ;)
|
// Disabled until we tidy up the CSS... ;)
|
||||||
<li><a href="/auth/logout">Sign out</a></li>
|
<li><a href="/auth/logout">Sign out</a></li>
|
||||||
-->
|
-->
|
||||||
|
<script>
|
||||||
|
var AuthUserDomain = "{{ user.domain() }}";
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% 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>
|
<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>
|
</ul>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue