From 276d1e085c39463a86e73439824b1ad2fd1b7869 Mon Sep 17 00:00:00 2001 From: Universe Date: Fri, 3 Mar 2023 10:07:19 +0900 Subject: [PATCH 1/2] init segment --- .../_firstparty-analytics/events/index.ts | 0 .../events/track-on-icon-load.ts | 0 .../events/track-on-icon-search.ts | 0 .../events/track-on-image-gen-prompt.ts | 0 .../events/track-on-photo-search.ts | 0 .../events/track-on-preview.ts | 0 .../events/track-on-publish.ts | 0 .../events/track-on-run-lint.ts | 0 .../events/track-on-selection-to-code.ts | 0 web/.env | 1 + web/package.json | 1 + web/pages/_app.tsx | 23 +++++++++- yarn.lock | 46 +++++++++++++++++-- 13 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 packages/_firstparty-analytics/events/index.ts create mode 100644 packages/_firstparty-analytics/events/track-on-icon-load.ts create mode 100644 packages/_firstparty-analytics/events/track-on-icon-search.ts create mode 100644 packages/_firstparty-analytics/events/track-on-image-gen-prompt.ts create mode 100644 packages/_firstparty-analytics/events/track-on-photo-search.ts create mode 100644 packages/_firstparty-analytics/events/track-on-preview.ts create mode 100644 packages/_firstparty-analytics/events/track-on-publish.ts create mode 100644 packages/_firstparty-analytics/events/track-on-run-lint.ts create mode 100644 packages/_firstparty-analytics/events/track-on-selection-to-code.ts diff --git a/packages/_firstparty-analytics/events/index.ts b/packages/_firstparty-analytics/events/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-icon-load.ts b/packages/_firstparty-analytics/events/track-on-icon-load.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-icon-search.ts b/packages/_firstparty-analytics/events/track-on-icon-search.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-image-gen-prompt.ts b/packages/_firstparty-analytics/events/track-on-image-gen-prompt.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-photo-search.ts b/packages/_firstparty-analytics/events/track-on-photo-search.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-preview.ts b/packages/_firstparty-analytics/events/track-on-preview.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-publish.ts b/packages/_firstparty-analytics/events/track-on-publish.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-run-lint.ts b/packages/_firstparty-analytics/events/track-on-run-lint.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/_firstparty-analytics/events/track-on-selection-to-code.ts b/packages/_firstparty-analytics/events/track-on-selection-to-code.ts new file mode 100644 index 00000000..e69de29b diff --git a/web/.env b/web/.env index 0d4b0019..c9f37829 100644 --- a/web/.env +++ b/web/.env @@ -8,3 +8,4 @@ NEXT_PUBLIC_UNSPLASH_TMP_LOCAL_CLIENT_ID= NEXT_PUBLIC_PUSHER_APP_KEY= NEXT_PUBLIC_PUSHER_APP_CLUSTER= NEXT_PUBLIC_CORS_GRIDA_API_KEY=get-it-from-https://github.com/gridaco/base/issues/23 +NEXT_PUBLIC_SEGMENT_WRITE_KEY= \ No newline at end of file diff --git a/web/package.json b/web/package.json index fd1def26..a97e42dc 100644 --- a/web/package.json +++ b/web/package.json @@ -8,6 +8,7 @@ "start": "next start -p 3303" }, "dependencies": { + "@segment/snippet": "^4.15.3", "app": "0.0.1", "languagedetect": "^2.0.0", "next": "^13.1.6", diff --git a/web/pages/_app.tsx b/web/pages/_app.tsx index e48b0acd..0096aa5b 100644 --- a/web/pages/_app.tsx +++ b/web/pages/_app.tsx @@ -1,9 +1,22 @@ import React, { useEffect } from "react"; import type { AppProps } from "next/app"; import { useRouter } from "next/router"; +import Script from "next/script"; +import * as snippet from "@segment/snippet"; import * as gtag from "../lib/gtag"; function WebApp({ Component, pageProps }: AppProps) { + const loadSegment = () => { + const options = { + apiKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY, + }; + if (process.env.NEXT_PUBLIC_NODE_ENV) { + return snippet.max(options); + } else { + return snippet.min(options); + } + }; + // region GA const router = useRouter(); useEffect(() => { @@ -17,6 +30,14 @@ function WebApp({ Component, pageProps }: AppProps) { }, [router.events]); // endregion GA - return ; + return ( + <> +