-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab8bfd8
commit b3d026f
Showing
15 changed files
with
1,100 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
|
||
# production | ||
/build | ||
/dist | ||
|
||
#vscode | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-react" | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* @copyright Copyright (C) 2022 AesirX. All rights reserved. | ||
* @license GNU General Public License version 3, see LICENSE. | ||
*/ | ||
|
||
import React from 'react'; | ||
export const AnalyticsContext = React.createContext(); | ||
|
||
export class AnalyticsContextProvider extends React.Component { | ||
render() { | ||
return ( | ||
<AnalyticsContext.Provider value={{ ...this.props.value }}> | ||
{this.props.children} | ||
</AnalyticsContext.Provider> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { AnalyticsContext } from './AnalyticsContextProvider'; | ||
import { initTracker, startTracker, endTracker } from '../utils'; | ||
const AnalyticsHandle = ({ router }) => { | ||
const AnalyticsStore = React.useContext(AnalyticsContext); | ||
const endPoint = process.env.NEXT_PUBLIC_ENDPOINT_ANALYTICS_URL; | ||
|
||
const handleStartTracker = useCallback(async () => { | ||
const responseStart = await startTracker( | ||
endPoint, | ||
AnalyticsStore.event_id, | ||
AnalyticsStore.uuid | ||
); | ||
responseStart.result.event_id && AnalyticsStore.setEventIDStart(responseStart.result.event_id); | ||
responseStart.result.uuid && AnalyticsStore.setUUIDStart(responseStart.result.uuid); | ||
}, [AnalyticsStore, endPoint]); | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
if (!AnalyticsStore.event_id && !AnalyticsStore.uuid) { | ||
const responseInit = await initTracker(endPoint); | ||
responseInit.result.event_id && AnalyticsStore.setEventID(responseInit.result.event_id); | ||
AnalyticsStore.setUUID(responseInit.result.uuid); | ||
} else { | ||
await handleStartTracker(); | ||
} | ||
}; | ||
init(); | ||
}, [AnalyticsStore.uuid]); | ||
|
||
useEffect(() => { | ||
const handleRouteChange = async () => { | ||
if (AnalyticsStore.uuid_start) { | ||
await endTracker(endPoint, AnalyticsStore.event_id_start, AnalyticsStore.uuid_start); | ||
await handleStartTracker(); | ||
} | ||
}; | ||
router.events.on('routeChangeComplete', handleRouteChange); | ||
|
||
return () => { | ||
router.events.off('routeChangeComplete', handleRouteChange); | ||
}; | ||
}, [router.events, AnalyticsStore.uuid_start]); | ||
|
||
return <></>; | ||
}; | ||
export default AnalyticsHandle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { AnalyticsContextProvider } from './AnalyticsContextProvider'; | ||
import AnalyticsHandle from './handle'; | ||
|
||
const AnalyticsNext = ({ router }) => { | ||
const [eventID, setEventID] = useState(); | ||
const [UUID, setUUID] = useState(); | ||
const [eventIDStart, setEventIDStart] = useState(); | ||
const [UUIDStart, setUUIDStart] = useState(); | ||
return ( | ||
<> | ||
<AnalyticsContextProvider | ||
value={{ | ||
event_id: eventID, | ||
uuid: UUID, | ||
event_id_start: eventIDStart, | ||
uuid_start: UUIDStart, | ||
setEventID: setEventID, | ||
setUUID: setUUID, | ||
setEventIDStart: setEventIDStart, | ||
setUUIDStart: setUUIDStart, | ||
}} | ||
> | ||
<AnalyticsHandle router={router}></AnalyticsHandle> | ||
</AnalyticsContextProvider> | ||
</> | ||
); | ||
}; | ||
export default AnalyticsNext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* @copyright Copyright (C) 2022 AesirX. All rights reserved. | ||
* @license GNU General Public License version 3, see LICENSE. | ||
*/ | ||
|
||
import React from 'react'; | ||
export const AnalyticsContext = React.createContext(); | ||
|
||
export class AnalyticsContextProvider extends React.Component { | ||
render() { | ||
return ( | ||
<AnalyticsContext.Provider value={{ ...this.props.value }}> | ||
{this.props.children} | ||
</AnalyticsContext.Provider> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useEffect } from 'react'; | ||
import { AnalyticsContext } from './AnalyticsContextProvider'; | ||
import { initTracker, startTracker, endTracker } from '../utils'; | ||
import { useLocation } from 'react-router-dom'; | ||
const AnalyticsHandle = ({ children }) => { | ||
const AnalyticsStore = React.useContext(AnalyticsContext); | ||
const endPoint = process.env.REACT_APP_ENDPOINT_ANALYTICS_URL; | ||
const { pathname } = useLocation(); | ||
useEffect(() => { | ||
const init = async () => { | ||
if (AnalyticsStore.uuid_start) { | ||
await endTracker(endPoint, AnalyticsStore.event_id_start, AnalyticsStore.uuid_start); | ||
} | ||
if (!AnalyticsStore.event_id && !AnalyticsStore.uuid) { | ||
const responseInit = await initTracker(endPoint); | ||
responseInit.result.event_id && AnalyticsStore.setEventID(responseInit.result.event_id); | ||
AnalyticsStore.setUUID(responseInit.result.uuid); | ||
} else { | ||
const responseStart = await startTracker( | ||
endPoint, | ||
AnalyticsStore.event_id, | ||
AnalyticsStore.uuid | ||
); | ||
responseStart.result.event_id && | ||
AnalyticsStore.setEventIDStart(responseStart.result.event_id); | ||
responseStart.result.uuid && AnalyticsStore.setUUIDStart(responseStart.result.uuid); | ||
} | ||
}; | ||
init(); | ||
}, [pathname, AnalyticsStore.uuid]); | ||
|
||
return <>{children}</>; | ||
}; | ||
export default AnalyticsHandle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { AnalyticsContextProvider } from './AnalyticsContextProvider'; | ||
import AnalyticsHandle from './handle'; | ||
const AnalyticsReact = ({ pathname, children }) => { | ||
const [eventID, setEventID] = useState(); | ||
const [UUID, setUUID] = useState(); | ||
const [eventIDStart, setEventIDStart] = useState(); | ||
const [UUIDStart, setUUIDStart] = useState(); | ||
return ( | ||
<> | ||
<AnalyticsContextProvider | ||
value={{ | ||
event_id: eventID, | ||
uuid: UUID, | ||
event_id_start: eventIDStart, | ||
uuid_start: UUIDStart, | ||
setEventID: setEventID, | ||
setUUID: setUUID, | ||
setEventIDStart: setEventIDStart, | ||
setUUIDStart: setUUIDStart, | ||
}} | ||
> | ||
<AnalyticsHandle pathname={pathname}>{children}</AnalyticsHandle> | ||
</AnalyticsContextProvider> | ||
</> | ||
); | ||
}; | ||
export default AnalyticsReact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import { AesirAnalytics } from './index'; | ||
import { AesirAnalytics } from './utils'; | ||
AesirAnalytics(); |
Oops, something went wrong.