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 = {
2222 "gatsby-plugin-styled-components" ,
2323 "gatsby-plugin-react-helmet" ,
2424 "custom-bytes-subscriber-count-plugin" ,
25+ "custom-plausible-plugin" ,
2526 {
2627 resolve : "gatsby-source-filesystem" ,
2728 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