File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
plugins/custom-plausible-plugin Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ module.exports = {
22
22
"gatsby-plugin-styled-components" ,
23
23
"gatsby-plugin-react-helmet" ,
24
24
"custom-bytes-subscriber-count-plugin" ,
25
+ "custom-plausible-plugin" ,
25
26
{
26
27
resolve : "gatsby-source-filesystem" ,
27
28
options : {
Original file line number Diff line number Diff line change
1
+ exports . onRouteUpdate = function ( { location } ) {
2
+ if (
3
+ process . env . NODE_ENV === `production` &&
4
+ typeof window . plausible === `object`
5
+ ) {
6
+ const pathIsExcluded =
7
+ location &&
8
+ typeof window . plausibleExcludePaths !== `undefined` &&
9
+ window . plausibleExcludePaths . some ( ( rx ) => rx . test ( location . pathname ) ) ;
10
+
11
+ if ( pathIsExcluded ) return null ;
12
+
13
+ window . plausible ( "pageview" ) ;
14
+ }
15
+ } ;
Original file line number Diff line number Diff line change
1
+ const React = require ( "react" ) ;
2
+
3
+ exports . onRenderBody = ( { setHeadComponents } ) => {
4
+ if ( process . env . NODE_ENV === "production" ) {
5
+ const scriptProps = {
6
+ defer : true ,
7
+ "data-domain" : "ui.dev" ,
8
+ src : `https://pl-proxy.uidotdev.workers.dev/js/script.js` ,
9
+ } ;
10
+
11
+ return setHeadComponents ( [
12
+ < script key = "custom-plausible-plugin" { ...scriptProps } > </ script > ,
13
+ < script
14
+ key = "custom-plausible-plugin-custom-events"
15
+ dangerouslySetInnerHTML = { {
16
+ __html : `
17
+ window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) };
18
+ ` ,
19
+ } }
20
+ /> ,
21
+ ] ) ;
22
+ }
23
+
24
+ return null ;
25
+ } ;
Original file line number Diff line number Diff line change
1
+ {}
You can’t perform that action at this time.
0 commit comments