Skip to content

Commit

Permalink
add tracking of events
Browse files Browse the repository at this point in the history
- creation of a quest chain
- failed creation of a quest chain
- error page
  • Loading branch information
vidvidvid committed Dec 9, 2022
1 parent 6839b47 commit 5885f7a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useRouter } from 'next/router';
import { useEffect } from 'react';

import { TrackEvent } from '@/utils/plausibleHelpers';

export const NotFoundPage: React.FC = () => {
const { push } = useRouter();
useEffect(() => {
push('/');
// @ts-ignore
window.plausible(TrackEvent.Error);
}, [push]);
return null;
};
Expand Down
26 changes: 26 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ import Document, {
} from 'next/document';

import { theme } from '../utils/theme';

export enum TrackEvent {
Signup = 'Signup',
Error = '404',
ChainCreated = 'Chain created',
}

type PlausibleArgs = [TrackEvent, () => void] | [TrackEvent];

declare global {
const plausible: {
(...args: PlausibleArgs): void;
q?: PlausibleArgs[];
};

interface Window {
plausible?: typeof plausible;
}
}

class TSDocument extends Document {
static async getInitialProps(
ctx: DocumentContext,
Expand All @@ -33,6 +53,12 @@ class TSDocument extends Document {
href="/logo.svg"
/>
<link rel="manifest" href="/manifest.json" />
<script
dangerouslySetInnerHTML={{
__html:
'window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }',
}}
/>
</Head>
<body
style={{
Expand Down
5 changes: 5 additions & 0 deletions pages/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { QUESTCHAINS_URL, SUPPORTED_NETWORKS } from '@/utils/constants';
import { awaitQuestChainAddress, waitUntilBlock } from '@/utils/graphHelpers';
import { handleError, handleTxLoading } from '@/utils/helpers';
import { Metadata, uploadMetadata } from '@/utils/metadata';
import { TrackEvent } from '@/utils/plausibleHelpers';
import { ipfsUriToHttp } from '@/utils/uriHelpers';
import { isSupportedNetwork, useWallet } from '@/web3';

Expand Down Expand Up @@ -219,9 +220,13 @@ const Create: React.FC = () => {
onOpen();

const chainAddress = await awaitQuestChainAddress(receipt);
// @ts-ignore
window.plausible(TrackEvent.ChainCreated);
setChainAddress(chainAddress);
toast.dismiss(tid);
} catch (error) {
// @ts-ignore
window.plausible(TrackEvent.ChainCreateFailed);
toast.dismiss(tid);
handleError(error);
}
Expand Down
6 changes: 6 additions & 0 deletions utils/plausibleHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum TrackEvent {
Signup = 'Signup',
Error = '404',
ChainCreated = 'Chain created',
ChainCreateFailed = 'Chain create failed',
}

0 comments on commit 5885f7a

Please sign in to comment.