Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-45786: Add Plausible.io tracking support #171

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading