Skip to content

Instantly share code, notes, and snippets.

@garth
Created October 8, 2019 17:04
Show Gist options
  • Save garth/6e0d4a14734ba9326b4483c3adbbdb5f to your computer and use it in GitHub Desktop.
Save garth/6e0d4a14734ba9326b4483c3adbbdb5f to your computer and use it in GitHub Desktop.
// This would be the client in the npm package
export const plausible: (arg: 'page' | 'trackPushState') => void = (window['plausible'] =
window['plausible'] ||
function(
...args: any[] // eslint-disable-line
) {
;(window['plausible'].q = window['plausible'].q || []).push(args)
})
const js = document.createElement('script')
js.id = 'plausible'
js.src = '/plausible/js/p.js' // the path might need to be configurable
js.async = true
document.head.appendChild(js)
import proxy from 'http-proxy-middleware'
// proxy to plausible
app.use( // app is an express app
'/plausible',
proxy({
target: 'https://plausible.io',
pathRewrite: { '^/plausible': '' },
})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment