From 916bbba7db59a49248229e982dee194394994ab9 Mon Sep 17 00:00:00 2001 From: Black-Hole1 <158blackhole@gmail.com> Date: Fri, 22 Apr 2022 17:28:24 +0800 Subject: [PATCH] refactor: add utm params in url --- src/pages/home/_components/AppsGrid.jsx | 5 ++++- src/util/addUTM.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/util/addUTM.js diff --git a/src/pages/home/_components/AppsGrid.jsx b/src/pages/home/_components/AppsGrid.jsx index 387efec5f..4592c241f 100644 --- a/src/pages/home/_components/AppsGrid.jsx +++ b/src/pages/home/_components/AppsGrid.jsx @@ -3,6 +3,9 @@ import Link from '@docusaurus/Link'; import { useColorMode } from '@docusaurus/theme-common'; import clsx from 'clsx'; import styles from './AppsGrid.module.scss'; +import { addUTM } from '../../../util/addUTM'; + +const utm = addUTM('home_page'); export default function AppsGrid({ list }) { const { isDarkTheme } = useColorMode(); @@ -11,7 +14,7 @@ export default function AppsGrid({ list }) {
{list.map((item) => ( diff --git a/src/util/addUTM.js b/src/util/addUTM.js new file mode 100644 index 000000000..882f3b5fc --- /dev/null +++ b/src/util/addUTM.js @@ -0,0 +1,17 @@ +/** + * + * @param {string} utmMedium + * @returns {(urlAddress: string) => string} + */ +export function addUTM(utmMedium) { + /** + * @param {string} urlAddress + */ + return function (urlAddress) { + const url = new URL(urlAddress); + url.searchParams.append('utm_source', 'electron'); + url.searchParams.append('utm_medium', utmMedium); + + return url.toString(); + }; +}