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

feat: add telemetry #272

Merged
merged 5 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions hooks/useTelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useState } from 'react';

import useSharedHook from '../lib/client/createSharedHook';

// eslint-disable-next-line react-hooks/rules-of-hooks
const [useTelemetry, setTelemetry] = useSharedHook(useState, null);

export { useTelemetry, setTelemetry };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be able to use telemetry object from anywhere.

2 changes: 2 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ export interface IssueDataViewInput {
// isRootIssueLoading: boolean;
// isPendingChildrenLoading: boolean;
}

export type BrowserMetricsProvider = import('@ipfs-shipyard/ignite-metrics').BrowserMetricsProvider
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safely getting the type here since importing it is sketchy with nextjs while this package is still cjs.

9 changes: 5 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ module.exports = {
webpack(config, options) {
config.experiments = config.experiments || {};
config.experiments.topLevelAwait = true;
// config.optimization = {
// providedExports: false,
// };
// options.nextRuntime = 'edge';
if (options.isServer) {
config.resolve.fallback = {
'@ipfs-shipyard/ignite-metrics': false,
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
}
}

return config;
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@emotion/react": "^11.10.4",
"@emotion/styled": "^11.10.4",
"@hookstate/core": "^4.0.0-rc21",
"@ipfs-shipyard/ignite-metrics": "https://github.com/ipfs-shipyard/ignite-metrics#feat/useStorageForBrowsers-with-dist",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update when ipfs-shipyard/ignite-metrics#64 is merged and new ignite-metrics is released

"@octokit/core": "^4.0.0",
"@octokit/graphql-schema": "^12.9.1",
"@octokit/plugin-retry": "^3.0.9",
Expand Down
30 changes: 28 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
import Head from 'next/head';

import { ChakraProvider } from '@chakra-ui/react';
import { noSSR } from 'next/dynamic';
import React, { useEffect } from 'react';

import React from 'react';
import { setTelemetry, useTelemetry } from '../hooks/useTelemetry';

import './style.css';
import { BrowserMetricsProvider } from '../lib/types';

function App({ Component, pageProps }) {
const telemetry: BrowserMetricsProvider|null = useTelemetry()
/**
* We have to do funky imports here to satisfy nextjs since this package is cjs and ignite-metrics is esm
*/
useEffect(() => {
(async() => {
// @ts-expect-error
const { BrowserMetricsProvider } = await noSSR(() => import('@ipfs-shipyard/ignite-metrics/browser-vanilla'), {})
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved

setTelemetry(new BrowserMetricsProvider({ appKey: '294089175b8268e44bc4e4fab572fe250d57b968' }))
SgtPooki marked this conversation as resolved.
Show resolved Hide resolved
})()
}, [])

useEffect(() => {
if (telemetry != null) {
// @ts-expect-error
window.telemetry = telemetry
// @ts-expect-error
window.removeMetricsConsent = () => telemetry.removeConsent(['minimal'])
// @ts-expect-error
window.addMetricsConsent = () => telemetry.addConsent(['minimal'])
}
}, [telemetry])

return (
<>
<Head>
Expand Down
Loading