From 615ceee05b1f14a37b77f9101027addb0f804c57 Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Mon, 30 Sep 2024 11:09:06 +0800 Subject: [PATCH 1/4] feat: ga amplitude --- docusaurus.config.ts | 17 ++++- src/js/amplitude.js | 144 +++++++++++++++++++++++++++++++++++++ src/js/google-analytics.js | 7 ++ 3 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 src/js/amplitude.js create mode 100644 src/js/google-analytics.js diff --git a/docusaurus.config.ts b/docusaurus.config.ts index dbfb44a..979dcba 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -1,5 +1,5 @@ -import {themes as prismThemes} from 'prism-react-renderer'; -import type {Config} from '@docusaurus/types'; +import { themes as prismThemes } from 'prism-react-renderer'; +import type { Config } from '@docusaurus/types'; import type * as Preset from '@docusaurus/preset-classic'; import footerLinks from "./config/footer-links.json"; import navbarLinks from "./config/navbar-links.json"; @@ -37,7 +37,18 @@ const config: Config = { }, plugins: ["docusaurus-plugin-hotjar"], - + scripts: [{ + src: "https://www.googletagmanager.com/gtag/js?id=G-PFZ0BCQHMY", + async: true, + }, + { + src: '/js/google-analytics.js', + async: false, + }, + { + src: '/js/amplitude.js', + async: false, + }], presets: [ [ "classic", diff --git a/src/js/amplitude.js b/src/js/amplitude.js new file mode 100644 index 0000000..4d33bfa --- /dev/null +++ b/src/js/amplitude.js @@ -0,0 +1,144 @@ +!(function () { + "use strict"; + !(function (e, t) { + var r = e.amplitude || { _q: [], _iq: {} }; + if (r.invoked) + e.console && + console.error && + console.error("Amplitude snippet has been loaded."); + else { + var n = function (e, t) { + e.prototype[t] = function () { + return ( + this._q.push({ + name: t, + args: Array.prototype.slice.call(arguments, 0), + }), + this + ); + }; + }, + s = function (e, t, r) { + return function (n) { + e._q.push({ + name: t, + args: Array.prototype.slice.call(r, 0), + resolve: n, + }); + }; + }, + o = function (e, t, r) { + e[t] = function () { + if (r) + return { + promise: new Promise( + s(e, t, Array.prototype.slice.call(arguments)) + ), + }; + }; + }, + i = function (e) { + for (var t = 0; t < m.length; t++) o(e, m[t], !1); + for (var r = 0; r < y.length; r++) o(e, y[r], !0); + }; + r.invoked = !0; + var a = t.createElement("script"); + (a.type = "text/javascript"), + (a.crossOrigin = "anonymous"), + (a.src = + "https://cdn.amplitude.com/libs/plugin-ga-events-forwarder-browser-0.3.4-min.js.gz"), + (a.onload = function () { + e.gaEventsForwarder && + e.gaEventsForwarder.plugin && + e.amplitude.add(e.gaEventsForwarder.plugin()); + }); + var c = t.createElement("script"); + (c.type = "text/javascript"), + (c.integrity = + "sha384-pY2pkwHaLM/6UIseFHVU3hOKr6oAvhLcdYkoRZyaMDWLjpM6B7nTxtOdE823WAOQ"), + (c.crossOrigin = "anonymous"), + (c.async = !0), + (c.src = + "https://cdn.amplitude.com/libs/analytics-browser-2.11.0-min.js.gz"), + (c.onload = function () { + e.amplitude.runQueuedFunctions || + console.log("[Amplitude] Error: could not load SDK"); + }); + var u = t.getElementsByTagName("script")[0]; + u.parentNode.insertBefore(a, u), u.parentNode.insertBefore(c, u); + for ( + var p = function () { + return (this._q = []), this; + }, + d = [ + "add", + "append", + "clearAll", + "prepend", + "set", + "setOnce", + "unset", + "preInsert", + "postInsert", + "remove", + "getUserProperties", + ], + l = 0; + l < d.length; + l++ + ) + n(p, d[l]); + r.Identify = p; + for ( + var g = function () { + return (this._q = []), this; + }, + v = [ + "getEventProperties", + "setProductId", + "setQuantity", + "setPrice", + "setRevenue", + "setRevenueType", + "setEventProperties", + ], + f = 0; + f < v.length; + f++ + ) + n(g, v[f]); + r.Revenue = g; + var m = [ + "getDeviceId", + "setDeviceId", + "getSessionId", + "setSessionId", + "getUserId", + "setUserId", + "setOptOut", + "setTransport", + "reset", + "extendSession", + ], + y = [ + "init", + "add", + "remove", + "track", + "logEvent", + "identify", + "groupIdentify", + "setGroup", + "revenue", + "flush", + ]; + i(r), + (r.createInstance = function (e) { + return (r._iq[e] = { _q: [] }), i(r._iq[e]), r._iq[e]; + }), + (e.amplitude = r); + } + })(window, document); +})(); + +amplitude.init("7652218546e8f6cc3d045e43a68830f6"); diff --git a/src/js/google-analytics.js b/src/js/google-analytics.js new file mode 100644 index 0000000..1f85175 --- /dev/null +++ b/src/js/google-analytics.js @@ -0,0 +1,7 @@ +window.dataLayer = window.dataLayer || []; +function gtag() { + dataLayer.push(arguments); +} +gtag("js", new Date()); + +gtag("config", "G-PFZ0BCQHMY"); From f50a439b890ae537a713e23713184887c806b66d Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Mon, 30 Sep 2024 11:33:10 +0800 Subject: [PATCH 2/4] feat: env --- .env.example | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index a001fad..1745b74 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -TYPESENSE_COLLECTION_NAME= -TYPESENSE_SERVER_HOST= -TYPESENSE_SEARCH_ONLY_APIKEY= -HOTJAR_ID= \ No newline at end of file +TYPESENSE_COLLECTION_NAME=abc +TYPESENSE_SERVER_HOST=abc +TYPESENSE_SEARCH_ONLY_APIKEY=abc +HOTJAR_ID=abc \ No newline at end of file From 41238db7bf9242e2a4b521cf0b74614a7bce5768 Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Mon, 30 Sep 2024 13:24:16 +0800 Subject: [PATCH 3/4] feat: change the order --- docusaurus.config.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 979dcba..5ac623e 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -1,6 +1,6 @@ -import { themes as prismThemes } from 'prism-react-renderer'; -import type { Config } from '@docusaurus/types'; -import type * as Preset from '@docusaurus/preset-classic'; +import { themes as prismThemes } from "prism-react-renderer"; +import type { Config } from "@docusaurus/types"; +import type * as Preset from "@docusaurus/preset-classic"; import footerLinks from "./config/footer-links.json"; import navbarLinks from "./config/navbar-links.json"; import remarkMath from "remark-math"; @@ -37,18 +37,20 @@ const config: Config = { }, plugins: ["docusaurus-plugin-hotjar"], - scripts: [{ - src: "https://www.googletagmanager.com/gtag/js?id=G-PFZ0BCQHMY", - async: true, - }, - { - src: '/js/google-analytics.js', - async: false, - }, - { - src: '/js/amplitude.js', - async: false, - }], + scripts: [ + { + src: "/js/amplitude.js", + async: true, + }, + { + src: "https://www.googletagmanager.com/gtag/js?id=G-PFZ0BCQHMY", + async: true, + }, + { + src: "/js/google-analytics.js", + async: true, + }, + ], presets: [ [ "classic", From 952d58ebe8cbfb16b95d450f7165bf162e0a0c38 Mon Sep 17 00:00:00 2001 From: AbigailDeng Date: Mon, 30 Sep 2024 13:45:18 +0800 Subject: [PATCH 4/4] feat: amplitude --- docusaurus.config.ts | 4 ++-- {src => static}/js/amplitude.js | 0 {src => static}/js/google-analytics.js | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {src => static}/js/amplitude.js (100%) rename {src => static}/js/google-analytics.js (100%) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 5ac623e..73f0c24 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -44,11 +44,11 @@ const config: Config = { }, { src: "https://www.googletagmanager.com/gtag/js?id=G-PFZ0BCQHMY", - async: true, + defer: true, }, { src: "/js/google-analytics.js", - async: true, + defer: true, }, ], presets: [ diff --git a/src/js/amplitude.js b/static/js/amplitude.js similarity index 100% rename from src/js/amplitude.js rename to static/js/amplitude.js diff --git a/src/js/google-analytics.js b/static/js/google-analytics.js similarity index 100% rename from src/js/google-analytics.js rename to static/js/google-analytics.js