Skip to content

Commit

Permalink
Merge pull request yelloworld-bot#60 from team-yello/main
Browse files Browse the repository at this point in the history
[feat] event 페이지 추가
  • Loading branch information
yelloworld-bot authored Mar 22, 2024
2 parents 0271f62 + ba3806b commit 6639f86
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions app/event/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';

import {
AMPLITUDE_KEY,
APP_STORE_URL,
GOOGLE_PLAY_URL,
LANDING_PAGE_URL,
} from '@/util/string';
import { useSearchParams } from 'next/navigation';
import React, { Suspense, useEffect } from 'react';
import { isAndroid, isIOS } from 'react-device-detect';
import * as amplitude from '@amplitude/analytics-browser';

export default function Page() {
return (
<>
<div>{'redirecting...'}</div>
<Suspense>
<GTMComponent />
</Suspense>
</>
);
}

const GTMComponent = () => {
const params = useSearchParams();

useEffect(() => {
if (typeof window !== 'undefined') {
amplitude.init(AMPLITUDE_KEY as string, { defaultTracking: true });

let redirectTo;
let platform;
if (isIOS) {
platform = 'iOS';
redirectTo = APP_STORE_URL;
} else if (isAndroid) {
redirectTo = GOOGLE_PLAY_URL;
platform = 'Android';
} else {
platform = 'others';
redirectTo = LANDING_PAGE_URL;
}
setTimeout(() => {
const gtag = window.gtag;
gtag('event', 'download_link', {
id: params.has('id') ? params.get('id') : 'null',
platform: platform,
});
amplitude.logEvent('download_link', {
id: params.has('id') ? (params.get('id') as string) : undefined,
});
window.location.replace(redirectTo);
}, 1000);
}
}, [params]);

return <div>{'data sending..'}</div>;
};

0 comments on commit 6639f86

Please sign in to comment.