a looooot
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { useEffect } from 'react';
|
||||
// import { mixan } from '@/analytics';
|
||||
import { OpenpanelProvider } from '@mixan-test/next';
|
||||
import type { AppProps } from 'next/app';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function MyApp({ Component, pageProps }: AppProps) {
|
||||
const router = useRouter();
|
||||
// useEffect(() => {
|
||||
// mixan.screenView();
|
||||
// return router.events.on('routeChangeComplete', () => {
|
||||
// mixan.screenView();
|
||||
// });
|
||||
// }, []);
|
||||
return <Component {...pageProps} />;
|
||||
return (
|
||||
<>
|
||||
<OpenpanelProvider
|
||||
clientId="0acce97f-1126-4439-b7ee-5d384e2fc94b"
|
||||
url="http://localhost:3333"
|
||||
trackScreenViews
|
||||
/>
|
||||
<Component {...pageProps} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import { Head, Html, Main, NextScript } from 'next/document';
|
||||
|
||||
export default function Document() {
|
||||
return (
|
||||
<Html>
|
||||
<Head>
|
||||
<script
|
||||
async
|
||||
src="/op.js"
|
||||
data-url="http://localhost:3333"
|
||||
data-client-id="0acce97f-1126-4439-b7ee-5d384e2fc94b"
|
||||
data-track-screen-views="1"
|
||||
data-track-outgoing-links="1"
|
||||
/>
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
@@ -1,17 +1,68 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
clear,
|
||||
decrement,
|
||||
increment,
|
||||
setProfile,
|
||||
trackEvent,
|
||||
} from '@mixan-test/next';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function Test() {
|
||||
const [id, setId] = useState('');
|
||||
const [auth, setAuth] = useState<string | null>(null);
|
||||
|
||||
function handleLogin() {
|
||||
if (id) {
|
||||
localStorage.setItem('auth', id);
|
||||
setAuth(id);
|
||||
}
|
||||
}
|
||||
|
||||
function handleLogout() {
|
||||
localStorage.removeItem('auth');
|
||||
setAuth(null);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setAuth(localStorage.getItem('auth') ?? null);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('auth', auth);
|
||||
|
||||
if (auth) {
|
||||
console.log('set profile?', auth);
|
||||
|
||||
setProfile({
|
||||
profileId: auth,
|
||||
});
|
||||
} else {
|
||||
clear();
|
||||
}
|
||||
}, [auth]);
|
||||
|
||||
if (auth === null) {
|
||||
return (
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Login with user id"
|
||||
onChange={(e) => setId(e.target.value)}
|
||||
/>
|
||||
<button onClick={handleLogin}>Login</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<Link href="/">Home</Link>
|
||||
<button
|
||||
onClick={() => {
|
||||
// @ts-expect-error
|
||||
window.openpanel.setUser({
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
email: 'john.doe@gmail.com',
|
||||
id: '1234',
|
||||
setProfile({
|
||||
firstName: 'Maja',
|
||||
lastName: 'Klara',
|
||||
profileId: auth,
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -19,16 +70,14 @@ export default function Test() {
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
// @ts-expect-error
|
||||
window.openpanel.increment('app_open', 1);
|
||||
increment('app_open', 1);
|
||||
}}
|
||||
>
|
||||
Increment
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
// @ts-expect-error
|
||||
window.openpanel.decrement('app_open', 1);
|
||||
decrement('app_open', 1);
|
||||
}}
|
||||
>
|
||||
Decrement
|
||||
@@ -43,8 +92,7 @@ export default function Test() {
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
// @ts-ignore
|
||||
window.openpanel.event('custom_click', {
|
||||
trackEvent('custom_click', {
|
||||
custom_string: 'test',
|
||||
custom_number: 1,
|
||||
});
|
||||
@@ -52,14 +100,7 @@ export default function Test() {
|
||||
>
|
||||
Trigger event
|
||||
</button>
|
||||
<button
|
||||
onClick={() => {
|
||||
// @ts-expect-error
|
||||
window.openpanel.clear();
|
||||
}}
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
<button onClick={handleLogout}>Logout</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user