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

V1 UTM Tag System #108

Merged
merged 2 commits into from
Dec 3, 2024
Merged
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
23 changes: 23 additions & 0 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ interface DynamicLinkData {
image_url?: string;
}

interface UTMData {
tag: string;
}

interface Props {
initialRoute: string;
metadata: {
Expand All @@ -26,10 +30,29 @@ interface Props {
export const getServerSideProps: GetServerSideProps = async ({
params,
req,
query,
}) => {
const slug = params?.slug as string[];
const slugRoute = slug.join("/");

if (query.utm_tag) {
const utmTag = query.utm_tag as string;

const { data: utmData, error: utmError } = await supabase
.from<UTMData>("utm")
.select()
.eq("tag", utmTag)
.single();

if (utmError) {
console.log("Could not find any utm entry for tag: ", utmTag);
} else if (utmData) {
await supabase.from("utm_clicks").insert({
utm_tag: utmData.tag,
});
}
}

const { data } = await supabase
.from<DynamicLinkData>("dynamic_links")
.select()
Expand Down
Loading