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

refactor: add utm params in url #219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion src/pages/home/_components/AppsGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -11,7 +14,7 @@ export default function AppsGrid({ list }) {
<div className={styles.appsContainer}>
{list.map((item) => (
<a
href={item.href}
href={utm(item.href)}
key={item.image}
className={clsx(styles.appCard, 'card')}
>
Expand Down
17 changes: 17 additions & 0 deletions src/util/addUTM.js
Original file line number Diff line number Diff line change
@@ -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();
};
}