Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ts: Convert `portico/google_analytics.js` to TypeScript.

Lalit Singh8eab7591a3e8
diff --git a/package.json b/package.json
index dd7c418d58e..08a77eef818 100644
--- a/package.json
+++ b/package.json
@@ -100,6 +100,7 @@
"@types/autosize": "^4.0.1",
"@types/blueimp-md5": "^2.18.0",
"@types/co-body": "^6.1.3",
+ "@types/gtag.js": "^0.0.20",
"@types/is-url": "^1.2.32",
"@types/jquery": "^3.3.31",
"@types/jquery.validation": "^1.16.7",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 76c064478c5..f5ea0f07036 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -311,6 +311,9 @@ importers:
'@types/co-body':
specifier: ^6.1.3
version: 6.1.3
+ '@types/gtag.js':
+ specifier: ^0.0.20
+ version: 0.0.20
'@types/is-url':
specifier: ^1.2.32
version: 1.2.32
@@ -2338,6 +2341,9 @@ packages:
resolution: {integrity: sha512-WCfD5Ht3ZesJUsONdhvm84dmzWOiOzOAqOncN0++w0lBw1o8OuDNJF2McvvCef/yBqb/HYRahp1BYtODFQ8bRg==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-wwAbk3SA2QeU67unN7zPxjEHmPmlXwZXZvQEpbEUQuMCRGgKyE1m6XDuTUA9b6pCGb/GqJmdfMOY5LuDjJSbbg==}
+
resolution: {integrity: sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==}
@@ -11229,6 +11235,8 @@ snapshots:
'@types/[email protected]': {}
+ '@types/[email protected]': {}
+
dependencies:
'@types/unist': 3.0.3
diff --git a/version.py b/version.py
index 9b46db1973c..1a62d30157f 100644
--- a/version.py
+++ b/version.py
@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 319 # Last bumped for message-link class
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
-PROVISION_VERSION = (301, 0) # bumped 2024-11-10 to remove commander, minimist, yargs
+PROVISION_VERSION = (301, 1) # bumped 2024-11-12 to add types for Google analytics
diff --git a/web/src/portico/ga-gtag.d.ts b/web/src/portico/ga-gtag.d.ts
new file mode 100644
index 00000000000..eaf7ea5756d
--- /dev/null
+++ b/web/src/portico/ga-gtag.d.ts
@@ -0,0 +1,16 @@
+/// <reference types="gtag.js" />
+
+/* global Gtag */
+
+/** * npm module name: "ga-gtag"
+ * version: "1.2.0"
+ */
+
+declare module "ga-gtag" {
+ export type ConfigParams = Gtag.GtagCommands["config"][1];
+
+ // Type reference: https://github.com/idmadj/ga-gtag/blob/eb7a97d153cbfedbc81344fd59123f737b8a5cb8/src/index.js
+ export const install: (trackingId: string, additionalConfigInfo?: ConfigParams) => void;
+
+ export const gtag: Gtag.Gtag;
+}
diff --git a/web/src/portico/google-analytics.js b/web/src/portico/google-analytics.js
deleted file mode 100644
index ad0171f17a9..00000000000
--- a/web/src/portico/google-analytics.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import {gtag, install} from "ga-gtag";
-
-import {page_params} from "../base_page_params";
-
-export let config;
-
-if (page_params.google_analytics_id !== undefined) {
- install(page_params.google_analytics_id);
- config = (info) => gtag("config", page_params.google_analytics_id, info);
-} else {
- config = () => {};
-}
diff --git a/web/src/portico/google-analytics.ts b/web/src/portico/google-analytics.ts
new file mode 100644
index 00000000000..5e2a9f2d7a0
--- /dev/null
+++ b/web/src/portico/google-analytics.ts
@@ -0,0 +1,17 @@
+import {gtag, install} from "ga-gtag";
+import type {ConfigParams} from "ga-gtag";
+
+import {page_params} from "../base_page_params";
+
+export let config: (info: ConfigParams) => void;
+
+if (page_params.google_analytics_id !== undefined) {
+ install(page_params.google_analytics_id);
+ config = (info) => {
+ gtag("config", page_params.google_analytics_id!, info);
+ };
+} else {
+ config = () => {
+ // No Google Analytics tracking configured.
+ };
+}