From 975731cd5bb8bb483943d3f182256f61fc6e1aea Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 24 Feb 2022 12:46:42 +0100 Subject: build(deps): add ackee-tracker --- package.json | 1 + yarn.lock | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/package.json b/package.json index d26ed28..3aab5a5 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ }, "dependencies": { "@babel/runtime": "^7.17.2", + "ackee-tracker": "^5.1.0", "dotenv": "^16.0.0", "dotenv-expand": "^8.0.1", "i18n-js": "^3.8.0", diff --git a/yarn.lock b/yarn.lock index 53d347f..34ab20d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1772,6 +1772,13 @@ accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.7: mime-types "~2.1.24" negotiator "0.6.2" +ackee-tracker@^5.1.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/ackee-tracker/-/ackee-tracker-5.1.0.tgz#6c41ea5357973347c7c67a26009053bcc0345def" + integrity sha512-A7iKkGyUnEXuOzxultQB7hnm4bStYCo1c38MYRRihBfqUP8AImhtZOODb00t9xrXs/BTsg06bz1MKpXeMs9sYw== + dependencies: + platform "^1.3.6" + acorn-import-assertions@^1.7.6: version "1.8.0" resolved "https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.0.tgz#ba2b5939ce62c238db6d93d81c9b111b29b855e9" @@ -6292,6 +6299,11 @@ pkg-dir@^4.1.0, pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +platform@^1.3.6: + version "1.3.6" + resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" + integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== + portfinder@^1.0.28: version "1.0.28" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.28.tgz#67c4622852bd5374dd1dd900f779f53462fac778" -- cgit v1.2.3 From 2693d745537a205f5994efc29f159df6a4c25ed2 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 24 Feb 2022 12:47:33 +0100 Subject: chore: remove Matomo references --- public/inc/tracker.php | 34 -- public/index.php | 1 - public/legal-notice.php | 17 +- public/license.php | 1 - public/matomo/config.php | 41 --- public/matomo/matomo-proxy.php | 36 -- public/matomo/matomo.php | 14 - public/matomo/piwik.php | 14 - .../plugins/HeatmapSessionRecording/configs.php | 9 - public/matomo/proxy.php | 367 --------------------- public/mentions-legales.php | 18 +- 11 files changed, 13 insertions(+), 539 deletions(-) delete mode 100644 public/inc/tracker.php delete mode 100644 public/matomo/config.php delete mode 100644 public/matomo/matomo-proxy.php delete mode 100644 public/matomo/matomo.php delete mode 100644 public/matomo/piwik.php delete mode 100644 public/matomo/plugins/HeatmapSessionRecording/configs.php delete mode 100644 public/matomo/proxy.php diff --git a/public/inc/tracker.php b/public/inc/tracker.php deleted file mode 100644 index b78cef7..0000000 --- a/public/inc/tracker.php +++ /dev/null @@ -1,34 +0,0 @@ - - * @copyright 2022 Armand Philippot - * @license MIT - * @link https://demo.armandphilippot.com/ - */ -?> - - - diff --git a/public/index.php b/public/index.php index debd008..b694f63 100644 --- a/public/index.php +++ b/public/index.php @@ -97,7 +97,6 @@ $dap_current_env = dap_get_current_env(); - diff --git a/public/legal-notice.php b/public/legal-notice.php index 65db82f..329ac44 100644 --- a/public/legal-notice.php +++ b/public/legal-notice.php @@ -91,16 +91,12 @@ $dap_current_env = dap_get_current_env(); MIT license.

Statistics and audience metrics

-

In order to adapt the site to visitor requests, the number of visits, the number of page views as well as the - activity of visitors to the site and their frequency of return are measured.

-

This site uses the Matomo statistics tool. The latter generates a cookie with a unique identifier, the - retention period of which is limited to 13 months. It is configured to hide the last 6 characters of your IP - address. Your browsing on the site is thus anonymized and the publisher can therefore under no circumstances - be traced back to a natural person by this means.

-

The Matomo statistics tool is one of the only tools validated by the French CNIL that does not require a - consent request.

- +

To obtain information on visitor behavior, the site uses Ackee. It is a privacy-friendly analysis software. + You can learn more about how it works and the data collected by going to the Ackee website.

+

This site uses the detailed mode in order to more easily adapt the site to its visitors. Thus, the tool + recovers the number of visits and the pages viewed but also the referring sites, the browser used or the + operating system.

@@ -121,7 +117,6 @@ $dap_current_env = dap_get_current_env();
- diff --git a/public/license.php b/public/license.php index e6e107f..eb9203a 100644 --- a/public/license.php +++ b/public/license.php @@ -113,7 +113,6 @@ $dap_current_env = dap_get_current_env(); - diff --git a/public/matomo/config.php b/public/matomo/config.php deleted file mode 100644 index 26959c3..0000000 --- a/public/matomo/config.php +++ /dev/null @@ -1,41 +0,0 @@ - $lastModified) { - sendHeader(sprintf("%s 304 Not Modified", $_SERVER['SERVER_PROTOCOL'])); - } else { - sendHeader('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - sendHeader('Content-Type: application/javascript; charset=UTF-8'); - - // Silent fail: hide Warning in 'matomo.js' response - if (empty($_GET) && empty($_POST)) { - if ($path !== 'matomo.php') { - $jsPath = 'piwik.js'; // for BC eg in case user uses an older version of Matomo - } else { - $jsPath = 'matomo.js'; - } - list($content, $httpStatus) = getHttpContentAndStatus($MATOMO_URL . $jsPath, $timeout, $user_agent); - } else { - list($content, $httpStatus) = getHttpContentAndStatus($MATOMO_URL . $filerequest, $timeout, $user_agent); - } - if ($matomoJs = $content) { - echo $matomoJs; - } else { - echo '/* there was an error loading matomo.js */'; - } - } - exit; -} -@ini_set('magic_quotes_runtime', 0); - -// 2) MATOMO.PHP PROXY: GET parameters found, this is a tracking request, we redirect it to Piwik -if (strpos($path, '?') === false) { - $path = $path . '?'; -} - -$extraQueryParams = array(); -if (strpos($path, 'piwik.php') === 0 || strpos($path, 'matomo.php') === 0) { - $extraQueryParams = array( - 'cip' => getVisitIp(), - 'token_auth' => $TOKEN_AUTH, - ); -} - -$url = $MATOMO_URL . $path; -$url .= http_build_query(array_merge($extraQueryParams, $_GET)); - -if (version_compare(PHP_VERSION, '5.3.0', '<')) { - - // PHP 5.2 breaks with the new 204 status code so we force returning the image every time - list($content, $httpStatus) = getHttpContentAndStatus($url . '&send_image=1', $timeout, $user_agent); - $content = sanitizeContent($content); - - forwardHeaders($content); - - echo $content; -} else { - // PHP 5.3 and above - list($content, $httpStatus) = getHttpContentAndStatus($url, $timeout, $user_agent); - $content = sanitizeContent($content); - - forwardHeaders($content); - - // Forward the HTTP response code - if (!headers_sent() && !empty($httpStatus)) { - header($httpStatus); - } - - echo $content; -} - -function sanitizeContent($content) -{ - global $TOKEN_AUTH; - global $MATOMO_URL; - global $PROXY_URL; - global $VALID_FILES; - - $matomoHost = parse_url($MATOMO_URL, PHP_URL_HOST); - $proxyHost = parse_url($PROXY_URL, PHP_URL_HOST); - - $content = str_replace($TOKEN_AUTH, '', $content); - $content = str_replace($MATOMO_URL, $PROXY_URL, $content); - $content = str_replace($matomoHost, $proxyHost, $content); - - if (isset($VALID_FILES)) { - foreach ($VALID_FILES as $filepath) { - // replace file paths to match the proxy and discard cb - $content = preg_replace('^' . $filepath . '(\?cb\=[a-z0-9]*)?^', $PROXY_URL . 'matomo-proxy.php?file=' . $filepath, $content); - } - } - - return $content; -} - -function forwardHeaders($content) -{ - global $httpResponseHeaders; - - $headersToForward = array( - 'content-type', - 'access-control-allow-origin', - 'access-control-allow-methods', - 'set-cookie', - ); - - foreach ($httpResponseHeaders as $header) { - $parts = explode(':', $header); - if (empty($parts[0])) { - continue; - } - - $name = trim(strtolower($parts[0])); - if (in_array($name, $headersToForward)) { - sendHeader($header); - } - } - - sendHeader('content-length: ' . strlen($content)); -} - -function getVisitIp() -{ - $ipKeys = array( - 'HTTP_X_FORWARDED_FOR', - 'HTTP_CLIENT_IP', - 'HTTP_CF_CONNECTING_IP', - ); - foreach ($ipKeys as $ipKey) { - if (isset($_SERVER[$ipKey]) - && filter_var($_SERVER[$ipKey], FILTER_VALIDATE_IP) !== false - ) { - return $_SERVER[$ipKey]; - } - } - return arrayValue($_SERVER, 'REMOTE_ADDR'); -} - -function transformHeaderLine($headerLine) -{ - // if we're not on an https protocol, make sure cookies do not have 'secure;' - if (empty($_SERVER['HTTPS']) && preg_match('/^set-cookie:/i', $headerLine)) { - $headerLine = str_replace('secure;', '', $headerLine); - } - return $headerLine; -} - -// captures a header line when using a curl request. would be better to use an anonymous function, but that would break -// PHP 5.2 support. -function handleHeaderLine($curl, $headerLine) -{ - global $httpResponseHeaders; - - $originalByteCount = strlen($headerLine); - - $headerLine = transformHeaderLine($headerLine); - $httpResponseHeaders[] = trim($headerLine); - - return $originalByteCount; -} - -function getHttpContentAndStatus($url, $timeout, $user_agent) -{ - global $httpResponseHeaders; - global $DEBUG_PROXY; - global $NO_VERIFY_SSL; - global $http_ip_forward_header; - - $useFopen = @ini_get('allow_url_fopen') == '1'; - - $header = array(); - $header[] = sprintf("Accept-Language: %s", str_replace(array("\n", "\t", "\r"), "", arrayValue($_SERVER, 'HTTP_ACCEPT_LANGUAGE', ''))); - - // NOTE: any changes made to Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker must be made here as well - if ((isset($_SERVER['HTTP_X_DO_NOT_TRACK']) && $_SERVER['HTTP_X_DO_NOT_TRACK'] === '1')) { - $header[] = "X-Do-Not-Track: 1"; - } - - if ((isset($_SERVER['HTTP_DNT']) && substr($_SERVER['HTTP_DNT'], 0, 1) === '1')) { - $header[] = "DNT: 1"; - } - - if (isset($_SERVER['HTTP_COOKIE'])) { - $header[] = "Cookie: " . $_SERVER['HTTP_COOKIE']; - } - - $stream_options = array( - 'http' => array( - 'user_agent' => $user_agent, - 'header' => $header, - 'timeout' => $timeout, - ), - ); - - if ($DEBUG_PROXY) { - $stream_options['http']['ignore_errors'] = true; - } - - if ($NO_VERIFY_SSL) { - $stream_options['ssl'] = array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ); - } - - // if there's POST data, send our proxy request as a POST - if (!empty($_POST)) { - $postBody = file_get_contents("php://input"); - - $stream_options['http']['method'] = 'POST'; - $stream_options['http']['header'][] = "Content-type: application/x-www-form-urlencoded"; - $stream_options['http']['header'][] = "Content-Length: " . strlen($postBody); - $stream_options['http']['content'] = $postBody; - - if (!empty($http_ip_forward_header)) { - $visitIp = getVisitIp(); - $stream_options['http']['header'][] = "$http_ip_forward_header: $visitIp"; - } - } - - if ($useFopen) { - $ctx = stream_context_create($stream_options); - - if ($DEBUG_PROXY) { - $content = file_get_contents($url, 0, $ctx); - } else { - $content = @file_get_contents($url, 0, $ctx); - } - - $httpStatus = ''; - if (isset($http_response_header[0])) { - $httpStatus = $http_response_header[0]; - $httpResponseHeaders = array_slice($http_response_header, 1); - $httpResponseHeaders = array_map('transformHeaderLine', $httpResponseHeaders); - } - } else { - if (!function_exists('curl_init')) { - throw new Exception("You must either set allow_url_fopen=1 in your PHP configuration, or enable the PHP Curl extension."); - } - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_USERAGENT, $stream_options['http']['user_agent']); - curl_setopt($ch, CURLOPT_HTTPHEADER, $stream_options['http']['header']); - curl_setopt($ch, CURLOPT_TIMEOUT, $stream_options['http']['timeout']); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $stream_options['http']['timeout']); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'handleHeaderLine'); - - if (!empty($stream_options['http']['method']) - && $stream_options['http']['method'] == 'POST' - ) { - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $stream_options['http']['content']); - } - - if (isset($stream_options['ssl']['verify_peer']) && $stream_options['ssl']['verify_peer'] == false) { - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - } - - if (isset($stream_options['ssl']['verify_peer_name']) && $stream_options['ssl']['verify_peer'] == false) { - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - } - - $content = curl_exec($ch); - $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if (!empty($httpStatus)) { - $httpStatus = 'HTTP/1.1 ' . $httpStatus; - } - curl_close($ch); - } - - return array( - $content, - $httpStatus, - ); -} - -function sendHeader($header, $replace = true) -{ - headers_sent() || header($header, $replace); -} - -function arrayValue($array, $key, $value = null) -{ - if (!empty($array[$key])) { - $value = $array[$key]; - } - return $value; -} diff --git a/public/mentions-legales.php b/public/mentions-legales.php index b96977d..4618fa2 100644 --- a/public/mentions-legales.php +++ b/public/mentions-legales.php @@ -91,16 +91,13 @@ $dap_current_env = dap_get_current_env(); licence MIT.

Statistiques et mesures d’audience

-

En vue d’adapter le site aux demandes des visiteurs, le nombre de visites, le nombre de pages vues ainsi que - de l’activité des visiteurs sur le site et leur fréquence de retour sont mesurées.

-

Ce site utilise l’outil de statistiques Matomo. Ce dernier génère un cookie avec un identifiant unique, dont - la durée de conservation est limitée à 13 mois. Il est configuré de manière à masquer les 6 derniers - caractères de votre adresse IP. Votre navigation sur le site est ainsi anonymisée et l’éditeur ne peut donc en - aucun cas remonter par ce biais à une personne physique.

-

L’outil de statistiques Matomo est l’un des seuls outils validés par la CNIL ne nécessitant pas de demande de - consentement.

- +

Pour obtenir des informations sur le comportement des visiteurs, le site utilise Ackee. Il s’agit d’un + logiciel d’analyse respectueux de la vie privée. Vous pouvez en apprendre plus sur le fonctionnement et les + données collectées en allant sur le site + d’Ackee.

+

Ce site utilise le mode détaillé afin d’adapter plus facilement le site à ses visiteurs. Ainsi, l'outil + récupère le nombre de visites et les pages vues mais également les sites référents, le navigateur utilisé ou + encore le système d'exploitation.

@@ -121,7 +118,6 @@ $dap_current_env = dap_get_current_env();
- -- cgit v1.2.3 From 137c36a5e65cae30e08edd49d25a831b6d996944 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 24 Feb 2022 12:48:44 +0100 Subject: build: configure webpack to use dotenv --- .env.example | 6 ++++++ config/webpack/webpack.common.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.env.example b/.env.example index 5c9f355..7dba9e2 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,12 @@ # Type: string - Either 'production', 'development' or a custom environment. CURRENT_ENV='development' +######################### +# Ackee configuration # +######################### +ACKEE_DOMAIN="www.ackeeDomain.com" +ACKEE_SITE_ID="your-id-string" + ######################### # webpack configuration # ######################### diff --git a/config/webpack/webpack.common.js b/config/webpack/webpack.common.js index c2155e9..5396cb4 100644 --- a/config/webpack/webpack.common.js +++ b/config/webpack/webpack.common.js @@ -1,5 +1,7 @@ const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin'); +const { DefinePlugin } = require('webpack'); +const dotenv = require('dotenv').config(); const paths = require('./paths'); module.exports = { @@ -102,5 +104,17 @@ module.exports = { { from: paths.src.images, to: 'images', noErrorOnMissing: true }, ], }), + new DefinePlugin({ + 'process.env': JSON.stringify(dotenv.parsed), + 'process.env.ACKEE_DOMAIN': JSON.stringify(process.env.ACKEE_DOMAIN), + 'process.env.ACKEE_SITE_ID': JSON.stringify(process.env.ACKEE_SITE_ID), + }), ], + resolve: { + fallback: { + fs: false, + path: false, + os: false, + }, + }, }; -- cgit v1.2.3 From 204a0c7b9665e3f85b3839a3007c1063bd436e77 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 24 Feb 2022 13:49:57 +0100 Subject: chore: set up Ackee --- src/js/app.js | 6 +++++- src/js/utilities/ackee.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/js/utilities/ackee.js diff --git a/src/js/app.js b/src/js/app.js index 48e3725..df6eff4 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -5,6 +5,7 @@ import { currentLocale, supportedLanguages, } from './i18n/i18n'; +import { createAckeeInstance, setAckeeRecord } from './utilities/ackee'; import { hideToBottom, hideToLeft, @@ -360,9 +361,12 @@ function setAppLocale() { } /** - * Initialize the website with the projects list. + * Initialize the website with the projects list and Ackee. */ function init() { + const ackee = createAckeeInstance(); + + setAckeeRecord(ackee); setAppLocale(); translateHTMLContent(); replaceLegalNoticeLink(); diff --git a/src/js/utilities/ackee.js b/src/js/utilities/ackee.js new file mode 100644 index 0000000..8584e2e --- /dev/null +++ b/src/js/utilities/ackee.js @@ -0,0 +1,42 @@ +import * as ackeeTracker from 'ackee-tracker'; + +/** + * Retrieve the Ackee website. + * @returns {string} The ackee website. + */ +function getAckeeDomain() { + return `https://${process.env.ACKEE_DOMAIN}`; +} + +/** + * Retrieve the domain Id. + * @returns {string} The domain Id configured in Ackee settings. + */ +function getAckeeSiteId() { + return process.env.ACKEE_SITE_ID; +} + +/** + * Create a new Ackee instance. + * @returns An Ackee instance. + */ +function createAckeeInstance() { + const domain = getAckeeDomain(); + + return ackeeTracker.create(domain, { + detailed: true, + ignoreLocalhost: true, + ignoreOwnVisits: true, + }); +} + +/** + * Create or update an Ackee record. + * @param {*} instance An Ackee Instance + */ +function setAckeeRecord(instance) { + const siteId = getAckeeSiteId(); + instance.record(siteId); +} + +export { createAckeeInstance, setAckeeRecord }; -- cgit v1.2.3