-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from Avantage-Numerique/dev-matomo
Ajout d'un outil de statistiques dans la navigation avec Matomo.
- Loading branch information
Showing
11 changed files
with
137 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,8 @@ | ||
|
||
|
||
const footerStaticScripts = () => { | ||
//Matomo | ||
/* | ||
|
||
<script> | ||
var _paq = window._paq = window._paq || []; | ||
//tracker methods like "setCustomDimension" should be called before "trackPageView" | ||
_paq.push(['trackPageView']); | ||
_paq.push(['enableLinkTracking']); | ||
(function() { | ||
var u="//stats.avnu.ca/"; | ||
_paq.push(['setTrackerUrl', u+'matomo.php']); | ||
_paq.push(['setSiteId', '1']); | ||
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> | ||
*/ | ||
return ( | ||
<script> | ||
//footer scripts. | ||
</script> | ||
<script></script> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {init, push} from "@socialgouv/matomo-next"; | ||
|
||
/** | ||
* Layer to manage the Matomo API and the Lib @socialgouv/matomo-next | ||
* It use the singleton patern and it's available throught the useWebStats hooks. | ||
*/ | ||
class Matomo { | ||
static _instance; | ||
url;//string | ||
id;//string | ||
_cookieChoices; | ||
currentSearchCount= 0; | ||
parameters = []; | ||
baseUrl; | ||
siteId; | ||
|
||
constructor() { | ||
this.parameters = []; | ||
this.url = process.env.NEXT_PUBLIC_MATOMO_URL; | ||
this.id = process.env.NEXT_PUBLIC_MATOMO_SITE_ID; | ||
} | ||
|
||
static instance() { | ||
if (Matomo._instance === undefined) { | ||
Matomo._instance = new Matomo(); | ||
} | ||
return Matomo._instance; | ||
} | ||
|
||
init(applicationCookiesParams) { | ||
this.cookieChoices = applicationCookiesParams; | ||
if (this.url && this.id) { | ||
init( | ||
{ | ||
url: this.url, | ||
siteId: this.id, | ||
//onRouteChangeComplete: this.onRouteChangeComplete, | ||
//excludeUrlsPatterns: [/^\/login.php/, /\?token=.+/], | ||
disableCookies: this.cookieChoices?.stats === true, | ||
} | ||
); | ||
return; | ||
} | ||
let message = this.url === undefined ? "L'url pour les statistiques sur matomo n'est pas défini" : ""; | ||
message += this.id === undefined ? "L'identifiant pour les statistique sur matomo n'est pas défini" : ""; | ||
console.erreur(message); | ||
} | ||
|
||
set cookieChoices(cookiesChoices) { | ||
this._cookieChoices = cookiesChoices; | ||
} | ||
get cookieChoices() { | ||
return this._cookieChoices | ||
} | ||
|
||
push(stats) { | ||
push(stats); | ||
} | ||
|
||
onRouteChangeComplete(path) { | ||
//needed for the searchCount uri query var ? | ||
if (path.startWidth("/searchResults")) { | ||
this.push(['trackSiteSearch', searchIndex, (nearTaxonomy?.nearestTaxonomy?.name ?? undefined), totalSearchRequestResults]); | ||
//push(["trackSiteSearch", q !== null && q !== void 0 ? q : ""]); | ||
} | ||
}; | ||
|
||
} | ||
|
||
export {Matomo}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {Matomo} from "@/src/monitoring/Matomo"; | ||
|
||
const useWebStats = () => { | ||
return Matomo.instance(); | ||
} | ||
|
||
export default useWebStats; |