Revue intégration Matomo

This commit is contained in:
Fabrice PENHOËT 2020-08-13 12:12:29 +02:00
parent 4f409167ba
commit d6c0f7db3a
8 changed files with 54 additions and 31 deletions

7
config/matomo.js Normal file
View File

@ -0,0 +1,7 @@
// Si non utilisé, supprimer l'appel des JS front-end puis recompiler.
// Revoir comment réorganiser cela sous-forme de module indépendant.
module.exports =
{
// Stats Matomo :
matomo: { url: "https://stats.le-fab-lab.com/", siteId: "5" },
};

View File

@ -18,6 +18,7 @@ import { addElement } from "./tools/dom.js";
import { helloDev } from "./tools/everywhere.js";
import { getDatasFromInputs } from "./tools/forms.js";
import { isEmpty } from "../../tools/main";
import { loadMatomo } from "./tools/matomo.js";
import { checkAnswerDatas, checkSession, getTimeDifference, setSession } from "./tools/users.js";
// Dictionnaires :
@ -47,6 +48,7 @@ const initialise = async () =>
}
else
{
loadMatomo();
myForm.style.display="block";
if(!isEmpty(getLocaly("message")))
{

View File

@ -12,6 +12,7 @@ const configFrontEnd = require("../../views/"+theme+"/config/"+lang+".js");
import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
import { addElement } from "./tools/dom.js";
import { helloDev } from "./tools/everywhere.js";
import { loadMatomo } from "./tools/matomo.js";
import { getUrlParams } from "./tools/url.js";
import { checkSession, getConfig, setSession } from "./tools/users.js";

View File

@ -8,6 +8,7 @@ const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");
import { getLocaly } from "./tools/clientstorage.js";
import { helloDev, updateAccountLink } from "./tools/everywhere.js";
import { loadMatomo } from "./tools/matomo.js";
import { checkSession } from "./tools/users.js";
helloDev();
@ -25,36 +26,7 @@ const initialise = async () =>
updateAccountLink(user.status, configTemplate);
}
else
{
// chargement de matomo
var _paq = window._paq = window._paq || [];
//ajout cnil :
_paq.push([function()
{
var self = this;
function getOriginalVisitorCookieTimeout()
{
var now = new Date(),
nowTs = Math.round(now.getTime() / 1000),
visitorInfo = self.getVisitorInfo();
var createTs = parseInt(visitorInfo[2]);
var cookieTimeout = 33696000; // 13 mois en secondes
var originalTimeout = createTs + cookieTimeout - nowTs;
return originalTimeout;
}
this.setVisitorCookieTimeout( getOriginalVisitorCookieTimeout() );
}]);
//--fin ajout cnil
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://stats.le-fab-lab.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '5']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
}
loadMatomo();
}
catch(e)
{

View File

@ -17,6 +17,7 @@ import { helloDev, updateAccountLink } from "./tools/everywhere.js";
import { getLocaly } from "./tools/clientstorage.js";
import { getDatasFromInputs } from "./tools/forms.js";
import { dateFormat, replaceAll } from "../../tools/main";
import { loadMatomo } from "./tools/matomo.js";
import { checkSession, getTimeDifference } from "./tools/users.js";
// Dictionnaires :
@ -45,6 +46,8 @@ const initialise = async () =>
updateAccountLink(user.status, configTemplate);// lien vers le compte adapté pour les utilisateurs connectés
checkPreviousResponses(user);
}
else
loadMatomo();
}
catch(e)
{

View File

@ -15,6 +15,7 @@ import { getLocaly, removeLocaly, saveLocaly } from "./tools/clientstorage.js";
import { addElement } from "./tools/dom.js";
import { helloDev } from "./tools/everywhere.js";
import { getDatasFromInputs, setAttributesToInputs } from "./tools/forms.js";
import { loadMatomo } from "./tools/matomo.js";
import { checkAnswerDatas, checkSession, getPassword, getTimeDifference } from "./tools/users.js";
// Dictionnaires :
@ -49,6 +50,7 @@ const initialise = async () =>
}
else
{
loadMatomo();
setAttributesToInputs(configUsers, myForm);
myForm.style.display="block";
}

View File

@ -16,6 +16,7 @@ const configTemplate = require("../../views/"+theme+"/config/"+lang+".js");
import { getLocaly, saveLocaly } from "./tools/clientstorage.js";
import { addElement } from "./tools/dom.js";
import { helloDev } from "./tools/everywhere.js";
import { loadMatomo } from "./tools/matomo.js";
import { getUrlParams } from "./tools/url.js";
import { checkSession } from "./tools/users.js";
@ -40,6 +41,7 @@ const initialise = async () =>
}
else
{
loadMatomo();
const datas=getUrlParams();
if(datas && datas.t!==undefined)
{

34
front/src/tools/matomo.js Normal file
View File

@ -0,0 +1,34 @@
import { matomo } from "../../../config/matomo.js";
// Fonction chargeant le code matomo
export const loadMatomo = () =>
{
// chargement de matomo
var _paq = window._paq = window._paq || [];
//ajout cnil :
_paq.push([function()
{
var self = this;
function getOriginalVisitorCookieTimeout()
{
var now = new Date(),
nowTs = Math.round(now.getTime() / 1000),
visitorInfo = self.getVisitorInfo();
var createTs = parseInt(visitorInfo[2]);
var cookieTimeout = 33696000; // 13 mois en secondes
var originalTimeout = createTs + cookieTimeout - nowTs;
return originalTimeout;
}
this.setVisitorCookieTimeout( getOriginalVisitorCookieTimeout() );
}]);
//--fin ajout cnil
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=matomo.url;
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', matomo.siteId]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
}