Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
VITE_BACKEND_URL=/api
# UTM settings for shared profile links (optional)
# Set any of these to enable UTM parameters on shared profile URLs.
VITE_UTM_SOURCE=twitter
VITE_UTM_MEDIUM=social
VITE_UTM_CAMPAIGN=share_profile
#VITE_UTM_TERM=
#VITE_UTM_CONTENT=
VITE_BACKEND_URL=http://localhost:3000/api/v1
VITE_DEFAULT_CHAIN_ID=84532
VITE_ANVIL_RPC_URL=http://127.0.0.1:8545
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh
sh ./scripts/check-no-package-lock.sh
pnpm lint-staged
npx lint-staged
6 changes: 5 additions & 1 deletion src/components/common/CreatorProfileHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';
import { Copy, Check, Share2 } from 'lucide-react';
import showToast from '@/utils/toast.util';
import appendUtmParams from '@/utils/utm.utils';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import VerifiedBadge from '@/components/common/VerifiedBadge';
Expand Down Expand Up @@ -32,7 +33,10 @@ const CreatorProfileHeader: React.FC<CreatorProfileHeaderProps> = ({
const [copied, setCopied] = useState(false);

const handleShare = async () => {
const url = window.location.href;
let url = window.location.href;

// Append UTM params when configured (no-op if none configured)
url = appendUtmParams(url);

if (navigator.share) {
try {
Expand Down
11 changes: 11 additions & 0 deletions src/utils/env.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const envSchema = z.object({
VITE_BASE_SEPOLIA_RPC_URL: z.string().default('https://sepolia.base.org'),
VITE_SEPOLIA_RPC_URL: z.string().optional(),
VITE_MAINNET_RPC_URL: z.string().optional(),
// UTM configuration for share links. Optional — when not provided, share URLs remain unchanged.
VITE_UTM_SOURCE: z.string().optional(),
VITE_UTM_MEDIUM: z.string().optional(),
VITE_UTM_CAMPAIGN: z.string().optional(),
VITE_UTM_TERM: z.string().optional(),
VITE_UTM_CONTENT: z.string().optional(),
});

export const env = envSchema.parse({
Expand All @@ -16,4 +22,9 @@ export const env = envSchema.parse({
VITE_BASE_SEPOLIA_RPC_URL: import.meta.env.VITE_BASE_SEPOLIA_RPC_URL,
VITE_SEPOLIA_RPC_URL: import.meta.env.VITE_SEPOLIA_RPC_URL,
VITE_MAINNET_RPC_URL: import.meta.env.VITE_MAINNET_RPC_URL,
VITE_UTM_SOURCE: import.meta.env.VITE_UTM_SOURCE,
VITE_UTM_MEDIUM: import.meta.env.VITE_UTM_MEDIUM,
VITE_UTM_CAMPAIGN: import.meta.env.VITE_UTM_CAMPAIGN,
VITE_UTM_TERM: import.meta.env.VITE_UTM_TERM,
VITE_UTM_CONTENT: import.meta.env.VITE_UTM_CONTENT,
});
50 changes: 50 additions & 0 deletions src/utils/utm.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { env } from '@/utils/env.utils';

export interface UtmParams {
utm_source?: string;
utm_medium?: string;
utm_campaign?: string;
utm_term?: string;
utm_content?: string;
}

export const getConfiguredUtmParams = (): UtmParams => {
const params: UtmParams = {};

if (env.VITE_UTM_SOURCE) params.utm_source = env.VITE_UTM_SOURCE;
if (env.VITE_UTM_MEDIUM) params.utm_medium = env.VITE_UTM_MEDIUM;
if (env.VITE_UTM_CAMPAIGN) params.utm_campaign = env.VITE_UTM_CAMPAIGN;
if (env.VITE_UTM_TERM) params.utm_term = env.VITE_UTM_TERM;
if (env.VITE_UTM_CONTENT) params.utm_content = env.VITE_UTM_CONTENT;

return params;
};

export const appendUtmParams = (inputUrl: string, overrideParams?: UtmParams): string => {
const configured = overrideParams ?? getConfiguredUtmParams();

// If no UTM params configured, return original URL unchanged
const keys = Object.keys(configured) as Array<keyof UtmParams>;
const hasAny = keys.some((k) => !!configured[k]);
if (!hasAny) return inputUrl;

try {
const url = new URL(inputUrl);

const search = url.searchParams;

if (configured.utm_source) search.set('utm_source', configured.utm_source);
if (configured.utm_medium) search.set('utm_medium', configured.utm_medium);
if (configured.utm_campaign) search.set('utm_campaign', configured.utm_campaign);
if (configured.utm_term) search.set('utm_term', configured.utm_term);
if (configured.utm_content) search.set('utm_content', configured.utm_content);

// Preserve hash and other parts — URL.toString() keeps them
return url.toString();
} catch {
// If URL parsing fails, fall back to original input
return inputUrl;
}
};

export default appendUtmParams;
Loading