From a30cdcfd6e408da04a55e8ca25972e315c22180c Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Wed, 12 Aug 2020 17:55:03 -0600 Subject: [PATCH] only use plausible in production --- nuxt.config.js | 12 ++---------- plugins/plausible.js | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 plugins/plausible.js diff --git a/nuxt.config.js b/nuxt.config.js index e5cb6fb..59ee584 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -19,15 +19,6 @@ export default { link: [ { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' } - ], - - script: [ - { - src: 'https://stats.elementary.io/js/index.js', - 'data-domain': 'builds.elementary.io', - async: true, - defer: true - } ] }, @@ -40,7 +31,8 @@ export default { }, plugins: [ - '~/plugins/auth' + '~/plugins/auth', + '~/plugins/plausible' ], publicRuntimeConfig: { diff --git a/plugins/plausible.js b/plugins/plausible.js new file mode 100644 index 0000000..33164cd --- /dev/null +++ b/plugins/plausible.js @@ -0,0 +1,24 @@ +export default (context, inject) => { + if (process.env.NODE_ENV === 'production') { + context.app.head.script.push({ + src: 'https://stats.elementary.io/js/index.js', + 'data-domain': 'builds.elementary.io', + async: true, + defer: true + }) + } + + context.app.head.script.push({ + innerHTML: ` + window.plausible = window.plausible || function() { + (window.plausible.q = window.plausible.q || []).push(arguments) + } + ` + }) + + inject('plausible', (...args) => { + if (global.window != null) { + window.plausible(...args) + } + }) +}