Skip to content

Commit

Permalink
Pretend we have consent for now, and expose Matomo env variables to t…
Browse files Browse the repository at this point in the history
…he frontend app
  • Loading branch information
Thomas Parisot committed Dec 1, 2021
1 parent 5e6e4ec commit f90ce35
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 16 deletions.
2 changes: 1 addition & 1 deletion front/gatsby/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDoNotTrack", true]);
// _paq.push(['requireConsent']);
_paq.push(['requireConsent']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
Expand Down
36 changes: 36 additions & 0 deletions front/gatsby/src/components/Footer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useCallback } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { Switch, Route, Link } from 'react-router-dom'

import styles from './header.module.scss'

function Footer () {
const dispatch = useDispatch()
const userHasConsent = useSelector(state => state.userPreferences.trackingConsent)
const toggleConsent = useCallback(() => dispatch({ type: 'USER_PREFERENCES_TOGGLE', key: 'trackingConsent' }), [])

return (<Switch>
<Route path="*/preview" />
<Route path="*">
<footer className={styles.footerContainer}>
<ul className={styles.footerList}>
<li>Stylo</li>
<li>
<a href="https://github.com/EcrituresNumeriques/stylo/releases" rel="noopener noreferrer" target="_blank">
Changelog
</a>
</li>
<li><Link to="/privacy">Privacy</Link></li>
{ import.meta.env.SNOWPACK_MATOMO_URL && (<li>
<label className={styles.consentLabel}>
<input type="checkbox" checked={userHasConsent} onChange={toggleConsent} disabled={true} />
I accept to share my navigation stats
</label>
</li>) }
</ul>
</footer>
</Route>
</Switch>)
}

export default Footer
3 changes: 1 addition & 2 deletions front/gatsby/src/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function Header () {
)

return (<Switch>
<Route path="*/preview">
</Route>
<Route path="*/preview" />
<Route path="*">
<header className={styles.headerContainer}>
<section className={styles.header}>
Expand Down
15 changes: 15 additions & 0 deletions front/gatsby/src/components/Privacy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import styles from '../components/Write/write.module.scss'

export default function Privacy () {
return (
<section className={styles.container}>
<article className={styles.simplePage}>
<h2>Privacy Terms</h2>

<p>Coming soon…</p>
</article>
</section>
)
}
7 changes: 6 additions & 1 deletion front/gatsby/src/components/Write/write.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@
}
}

.error {
.simplePage {
background-color: $extra-background-color;
box-shadow: 1px 2px 4px rgba(0, 0, 0, .3);
margin: 5em auto;
padding: 10em 2em;
width: 50%;
}

.error {
@extend .simplePage;
color: $error-color;
}

Expand Down
24 changes: 24 additions & 0 deletions front/gatsby/src/components/header.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,27 @@
margin: 0 .2em;
vertical-align: middle;
}

.footerContainer {
margin: 1em 0;
text-align: center;
}

.footerList {
list-style: none;

> li {
display: inline;

&:not(:last-child):after {
content: "";
margin: 0 .5em;
}
}
}

.consentLabel {
cursor: pointer;
font-size: .8em;
vertical-align: middle;
}
18 changes: 18 additions & 0 deletions front/gatsby/src/createReduxStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const initialState = {
charCountPlusSpace: 0,
citationNb: 0,
},
userPreferences: {
trackingConsent: true /* default value should be false */
}
}

const reducer = createReducer(initialState, {
Expand All @@ -56,6 +59,9 @@ const reducer = createReducer(initialState, {
UPDATE_ARTICLE_STRUCTURE: updateArticleStructure,
UPDATE_ARTICLE_BIB: updateArticleBib,

// user preferences reducers
USER_PREFERENCES_TOGGLE: toggleUserPreferences,

SET_ARTICLE_VERSIONS: setArticleVersions,
SET_WORKING_ARTICLE_UPDATED_AT: setWorkingArticleUpdatedAt,
SET_WORKING_ARTICLE_TEXT: setWorkingArticleText,
Expand Down Expand Up @@ -287,6 +293,18 @@ function toggleArticlePreferences (state, { key, value }) {
}
}

function toggleUserPreferences (state, { key }) {
const { userPreferences } = state

return {
...state,
userPreferences: {
...userPreferences,
[key]: !userPreferences[key]
}
}
}

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

export default () => createStore(reducer, composeEnhancers(
Expand Down
23 changes: 11 additions & 12 deletions front/gatsby/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getUserProfile } from './helpers/userProfile'
import { getApplicationConfig } from './helpers/applicationConfig'

import Header from './components/Header'
import Footer from './components/Footer'
import Register from './components/Register'
import PrivateRoute from './components/PrivateRoute'
import NotFound from './components/404'
Expand All @@ -28,6 +29,7 @@ const Articles = lazy(() => import('./components/Articles'))
const Credentials = lazy(() => import('./components/Credentials'))
const Write = lazy(() => import('./components/Write/Write'))
const ArticlePreview = lazy(() => import('./components/ArticlePreview'))
const Privacy = lazy(() => import('./components/Privacy'))

const store = createStore()

Expand All @@ -41,22 +43,15 @@ const store = createStore()
)
})()

<<<<<<< HEAD
=======
const ArticleID = (props) => {
const { id, version, compareTo } = useParams()
return (
<App layout="fullPage">
<Write {...props} id={id} version={version} compareTo={compareTo} />
</App>
)
}

const TrackPageViews = () => {
const history = useHistory()

history.listen(({ pathname, search, state }, action) => {
/* global _paq */

//@todo do this dynamically, based on a subscription to the store
//otherwise, we should use _paq.push(['forgetConsentGiven'])
_paq.push(['setConsentGiven'])
_paq.push(['setCustomUrl', '/' + pathname])
//_paq.push(['setDocumentTitle', 'My New Title'])
_paq.push(['trackPageView'])
Expand All @@ -65,7 +60,6 @@ const TrackPageViews = () => {
return null
}

>>>>>>> f10a6a4 (Track page views on router history change)
render(
<React.StrictMode>
<Provider store={store}>
Expand Down Expand Up @@ -108,6 +102,9 @@ render(
<PrivateRoute path={`/article/:id`}>
<Write />
</PrivateRoute>
<Route exact path="/privacy">
<Privacy />
</Route>
<Route exact path="/ux">
<h2>Buttons</h2>
<h4>Primary</h4>
Expand Down Expand Up @@ -145,6 +142,8 @@ render(
</Route>
</Switch>
</App>

<Footer />
</Router>
</Provider>
</React.StrictMode>,
Expand Down
1 change: 1 addition & 0 deletions front/gatsby/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { NODE_ENV, SNOWPACK_MATOMO_URL, SNOWPACK_MATOMO_SITE_ID } = env
// https://vitejs.dev/config/
export default defineConfig({
base: env.DEPLOY_PRIME_URL ?? '/',
envPrefix: 'SNOWPACK_',
build: {
outDir: 'build',
sourcemap: Boolean(env.ENABLE_SOURCEMAPS),
Expand Down

0 comments on commit f90ce35

Please sign in to comment.