Skip to content

Commit

Permalink
Merge pull request #197 from vietredweb/fix-darkmode
Browse files Browse the repository at this point in the history
Tracking SOP, Fix darkmode
  • Loading branch information
lunguyenhat authored Jan 31, 2024
2 parents 7344130 + 40cf9b1 commit 5e75d60
Show file tree
Hide file tree
Showing 20 changed files with 1,751 additions and 87 deletions.
11 changes: 6 additions & 5 deletions src/AnalyticsNext/handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import { startTracker, endTracker, endTrackerVisibilityState } from '../utils/in

interface AnalyticsHandle {
router: any;
attributes: any;
children?: ReactNode;
}

const AnalyticsHandle = ({ router, children }: AnalyticsHandle) => {
const AnalyticsHandle = ({ router, attributes, children }: AnalyticsHandle) => {
const AnalyticsStore = React.useContext(AnalyticsContext);
const endPoint = process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL;
const [prevRoute, setPrevRoute] = useState<string>('');
const handleStartTracker = useCallback(
async (prevRoute: string) => {
async (prevRoute: string, attributes: any) => {
const referer = prevRoute ? prevRoute : '';
window['referer'] = referer;
const responseStart = await startTracker(endPoint, '', referer);
const responseStart = await startTracker(endPoint, '', referer, '', attributes);
responseStart?.event_uuid && AnalyticsStore.setEventID(responseStart.event_uuid);
responseStart?.visitor_uuid && AnalyticsStore.setUUID(responseStart.visitor_uuid);
},
Expand All @@ -26,7 +27,7 @@ const AnalyticsHandle = ({ router, children }: AnalyticsHandle) => {
const init = async () => {
if (!AnalyticsStore.visitor_uuid) {
setPrevRoute(router.asPath);
await handleStartTracker(router.asPath);
await handleStartTracker(router.asPath, attributes);
}
};
init();
Expand All @@ -37,7 +38,7 @@ const AnalyticsHandle = ({ router, children }: AnalyticsHandle) => {
setPrevRoute(router.asPath);
if (AnalyticsStore.visitor_uuid) {
endTracker(endPoint, window['event_uuid'], AnalyticsStore.visitor_uuid);
await handleStartTracker(prevRoute);
await handleStartTracker(prevRoute, attributes);
}
};
router.events.on('routeChangeComplete', handleRouteChange);
Expand Down
27 changes: 20 additions & 7 deletions src/AnalyticsNext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,37 @@ import { NextRouter } from 'next/router';
import dynamic from 'next/dynamic';

const ConsentComponent = dynamic(() => import('../Components/Consent'), { ssr: false });
const ConsentComponentCustom = dynamic(() => import('../Components/ConsentCustom'), { ssr: false });

interface AnalyticsNext {
router: NextRouter;
attributes: any;
customLayout?: boolean;
children?: ReactNode;
}

const AnalyticsNext = ({ router, children }: AnalyticsNext) => {
const AnalyticsNext = ({ router, attributes, customLayout = false, children }: AnalyticsNext) => {
return (
<>
<AnalyticsContextProvider>
<AnalyticsHandle router={router}>
<AnalyticsHandle router={router} attributes={attributes}>
{children}
{process.env.NEXT_PUBLIC_DISABLE_ANALYTICS_CONSENT !== 'true' && (
<ConsentComponent
endpoint={process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL}
networkEnv={process.env.NEXT_PUBLIC_CONCORDIUM_NETWORK}
aesirXEndpoint={process.env.NEXT_PUBLIC_ENDPOINT_URL ?? 'https://api.aesirx.io'}
/>
<>
{customLayout ? (
<ConsentComponentCustom
endpoint={process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL}
networkEnv={process.env.NEXT_PUBLIC_CONCORDIUM_NETWORK}
aesirXEndpoint={process.env.NEXT_PUBLIC_ENDPOINT_URL ?? 'https://api.aesirx.io'}
/>
) : (
<ConsentComponent
endpoint={process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL}
networkEnv={process.env.NEXT_PUBLIC_CONCORDIUM_NETWORK}
aesirXEndpoint={process.env.NEXT_PUBLIC_ENDPOINT_URL ?? 'https://api.aesirx.io'}
/>
)}
</>
)}
</AnalyticsHandle>
</AnalyticsContextProvider>
Expand Down
5 changes: 5 additions & 0 deletions src/Assets/check_circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/Assets/check_line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/Assets/checkbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/Assets/checkbox_active.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5e75d60

Please sign in to comment.