Skip to content

Commit

Permalink
Add Plausible.io tracking support
Browse files Browse the repository at this point in the history
Setting up Plausible's tracking is done with
https://github.com/4lejandrito/next-plausible

Tracking is optional; by not setting the plausibleDomain configuration
the tracking is not enabled.
  • Loading branch information
jonathansick committed Aug 15, 2024
1 parent 7eb441e commit 55ff9ab
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-crabs-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'squareone': minor
---

Add support for Plausible.io analytics

In Squareone, set the `plausibleDomain` configuration to the Plausible tracking domain. E.g. data.lsst.cloud for the RSP. To disable Plausible tracking where it isn't supported, set this configuration to `null`.
1 change: 1 addition & 0 deletions apps/squareone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"js-yaml": "^4.1.0",
"next": "^12.2.4",
"next-mdx-remote": "^4.4.1",
"next-plausible": "^3.12.1",
"next-themes": "^0.2.0",
"prop-types": "^15.8.1",
"react": "^17.0.2",
Expand Down
5 changes: 5 additions & 0 deletions apps/squareone/squareone.config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"type": "string",
"title": "COmanage registry URL (e.g. https://id.lsst.cloud). Omit or set as null for non-COmanage deployments."
},
"plausibleDomain": {
"type": "string",
"title": "Plausible tracking domain",
"description": "Domain (e.g. data.lsst.cloud) for Plausible tracking. Omit to disable Plausible."
},
"apiAspectPageMdx": {
"type": "string",
"title": "/api-aspect Page MDX content"
Expand Down
22 changes: 18 additions & 4 deletions apps/squareone/src/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import PropTypes from 'prop-types';
import getConfig from 'next/config';
import { ThemeProvider } from 'next-themes';
import PlausibleProvider from 'next-plausible';

// Global CSS
// Keep these imports in sync with .storybook/preview.js (Next can't import
Expand All @@ -15,33 +16,46 @@ import '../styles/icons';

import Page from '../components/Page';

function MyApp({ Component, pageProps, baseUrl, semaphoreUrl }) {
function MyApp({
Component,
pageProps,
baseUrl,
semaphoreUrl,
plausibleDomain,
}) {
// Use the content layout defined by the page component, if avaialble.
// Otherwise, the page itself is used as the content area layout container.
const getLayout = Component.getLayout || ((page) => page);

/* eslint-disable react/jsx-props-no-spreading */
return (
const coreApp = (
<ThemeProvider defaultTheme="system">
<Page baseUrl={baseUrl} semaphoreUrl={semaphoreUrl}>
{getLayout(<Component {...pageProps} />)}
</Page>
</ThemeProvider>
);
/* eslint-enable react/jsx-props-no-spreading */
if (!plausibleDomain) {
return coreApp;
}
return (
<PlausibleProvider domain={plausibleDomain}>{coreApp}</PlausibleProvider>
);
}

MyApp.getInitialProps = async () => {
const { publicRuntimeConfig } = getConfig();
const { baseUrl, semaphoreUrl } = publicRuntimeConfig;
return { baseUrl, semaphoreUrl };
const { baseUrl, semaphoreUrl, plausibleDomain } = publicRuntimeConfig;
return { baseUrl, semaphoreUrl, plausibleDomain };
};

MyApp.propTypes = {
Component: PropTypes.elementType.isRequired,
pageProps: PropTypes.object.isRequired,
baseUrl: PropTypes.string.isRequired,
semaphoreUrl: PropTypes.string,
plausibleDomain: PropTypes.string,
};

export default MyApp;
15 changes: 15 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 55ff9ab

Please sign in to comment.