Skip to content

Commit

Permalink
V1 UTM Tag System (#108)
Browse files Browse the repository at this point in the history
* Add in code to check for utm tags in queries

* Fix eslint
  • Loading branch information
iyasinn authored Dec 3, 2024
1 parent a5ff530 commit e682ce2
Showing 1 changed file with 23 additions and 0 deletions.
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

0 comments on commit e682ce2

Please sign in to comment.