-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
<template> | ||
<PrivacyNotice /> | ||
<router-view /> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import PrivacyNotice from 'src/components/PrivacyNotice.vue' | ||
export default ({ | ||
name: 'App' | ||
name: 'App', | ||
components: { | ||
PrivacyNotice | ||
} | ||
}) | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import { useQuasar } from 'quasar' | ||
export default defineComponent({ | ||
name: 'PrivacyNotice', | ||
setup () { | ||
const $q = useQuasar() | ||
const tempWindow = window as any | ||
Check failure on line 9 in src/components/PrivacyNotice.vue GitHub Actions / lint
|
||
const _paq = tempWindow._paq = tempWindow._paq || [] | ||
Check failure on line 11 in src/components/PrivacyNotice.vue GitHub Actions / lint
Check failure on line 11 in src/components/PrivacyNotice.vue GitHub Actions / lint
Check failure on line 11 in src/components/PrivacyNotice.vue GitHub Actions / lint
|
||
const accept = () => { | ||
_paq.push(['rememberConsentGiven']) | ||
Check failure on line 14 in src/components/PrivacyNotice.vue GitHub Actions / lint
|
||
_paq.push(['setConsentGiven']) | ||
Check failure on line 15 in src/components/PrivacyNotice.vue GitHub Actions / lint
|
||
} | ||
const refuse = () => { | ||
_paq.push(['forgetConsentGiven']) | ||
} | ||
$q.notify({ | ||
message: 'We use <a href="/cookies" class="link-over-primary" target="_blank">cookies</a> with <a href="https://matomo.org" class="link-over-primary" target="_black">matomo.org</a> to anonymously track usage and improve our app. Do you accept?', | ||
color: 'primary', | ||
progress: true, | ||
timeout: 0, | ||
actions: [ | ||
{ label: 'Accept', color: 'white', handler: accept }, | ||
{ label: 'Refuse', color: 'white', handler: refuse } | ||
], | ||
html: true | ||
}) | ||
return { | ||
} | ||
} | ||
}) | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><%= productName %></title> | ||
|
||
<head> | ||
<title> | ||
<%= productName %> | ||
</title> | ||
|
||
<meta charset="utf-8"> | ||
<meta name="description" content="<%= productDescription %>"> | ||
<meta name="format-detection" content="telephone=no"> | ||
<meta name="msapplication-tap-highlight" content="no"> | ||
<meta name="viewport" content="initial-scale=1, maximum-scale=5, minimum-scale=1, width=device-width<% if (ctx.mode.cordova || ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>"> | ||
<meta name="viewport" | ||
content="initial-scale=1, maximum-scale=5, minimum-scale=1, width=device-width<% if (ctx.mode.cordova || ctx.mode.capacitor) { %>, viewport-fit=cover<% } %>"> | ||
<link rel="icon" type="image/png" href="favicon.png"> | ||
</head> | ||
<body> | ||
|
||
<!-- Matomo --> | ||
<script> | ||
var _paq = window._paq = window._paq || []; | ||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ | ||
console.log('sup') | ||
_paq.push(['requireConsent']); | ||
_paq.push(['trackPageView']); | ||
_paq.push(['enableLinkTracking']); | ||
(function () { | ||
var u = "//matomo.research.software/"; | ||
_paq.push(['setTrackerUrl', u + 'matomo.php']); | ||
_paq.push(['setSiteId', '4']); | ||
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0]; | ||
g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s); | ||
})(); | ||
</script> | ||
<!-- End Matomo Code --> | ||
|
||
</head> | ||
|
||
<body> | ||
<!-- DO NOT touch the following DIV --> | ||
<div id="q-app"></div> | ||
</body> | ||
</body> | ||
|
||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copied from https://github.com/research-software-directory/RSD-as-a-service/blob/main/frontend/components/cookies/nodeCookies.ts | ||
|
||
import { IncomingMessage } from 'http' | ||
import cookie from 'cookie' | ||
|
||
export type Matomo = { | ||
id: string | null | ||
consent: boolean | null | ||
} | ||
|
||
/** | ||
* Extract Matomo cookies | ||
* Available only on the server side, using plain Node request | ||
* @param req | ||
* @returns Session | ||
*/ | ||
export function getMatomoCookies (req: IncomingMessage) { | ||
// check for cookies | ||
if (req?.headers?.cookie) { | ||
// parse cookies from node request | ||
const cookies = cookie.parse(req.headers.cookie) | ||
// validate and decode | ||
return { | ||
mtm_consent: cookies?.mtm_consent, | ||
mtm_consent_removed: cookies?.mtm_consent_removed | ||
} | ||
} else { | ||
return { | ||
mtm_consent: undefined, | ||
mtm_consent_removed: undefined | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Extract matomo consent based on cookies | ||
* Available only on the server side, using plain Node request | ||
* @param req | ||
* @returns Session | ||
*/ | ||
export function getMatomoConsent (req:IncomingMessage) { | ||
// check for cookies | ||
// console.log('getMatomoConsent...', req) | ||
if (req?.headers?.cookie) { | ||
const matomo = getMatomoCookies(req) | ||
if (matomo?.mtm_consent) { | ||
return { | ||
matomoConsent: true | ||
} | ||
} else if (matomo?.mtm_consent_removed) { | ||
return { | ||
matomoConsent: false | ||
} | ||
} | ||
} | ||
return { | ||
matomoConsent: null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copied from https://github.com/research-software-directory/RSD-as-a-service/blob/main/frontend/components/cookies/nodeCookies.test.ts | ||
|
||
import { describe, expect, it, jest } from '@jest/globals' | ||
Check warning on line 3 in test/jest/__tests__/store/matomo.jest.spec.ts GitHub Actions / lint
|
||
import { getMatomoConsent } from 'src/store/nodeCookies' | ||
|
||
const mockRequest:any = { | ||
headers: { | ||
cookie: '_pk_id.1.a7f1=7b08ec6de0eadf14.1664460134.; mtm_consent=1664460134155; _pk_ref.1.a7f1=%5B%22%22%2C%22%22%2C1670956090%2C%22https%3A%2F%2Fconnect.surfconext.nl%2F%22%5D; _pk_ses.1.a7f1=1' | ||
} | ||
} | ||
|
||
it('extracts mtm_consent cookie from request', () => { | ||
// extract matomo cookie | ||
const { matomoConsent } = getMatomoConsent(mockRequest) | ||
// assert consent is true | ||
expect(matomoConsent).toBe(true) | ||
}) | ||
|
||
it('extracts mtm_consent_removed cookie from request', () => { | ||
mockRequest.headers.cookie = 'mtm_consent_removed=1664460134155;' | ||
// extract matomo cookie | ||
const { matomoConsent } = getMatomoConsent(mockRequest) | ||
// expect consent is false | ||
expect(matomoConsent).toBe(false) | ||
}) | ||
|
||
it('extracts mtm_consent is not present', () => { | ||
mockRequest.headers.cookie = '_pk_ses.1.a7f1=1;' | ||
// extract matomo cookie | ||
const { matomoConsent } = getMatomoConsent(mockRequest) | ||
// expect consent is false | ||
expect(matomoConsent).toBe(null) | ||
}) |