-
Notifications
You must be signed in to change notification settings - Fork 467
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
Showing
21 changed files
with
126 additions
and
143 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
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,8 +1,2 @@ | ||
// HOC for wrapping a component with content analytics capabilities | ||
export * from './lib/react/components/withContentAnalytics'; | ||
|
||
// Hook for tracking analytics events | ||
export * from './lib/react/hook/useAnalyticTracker'; | ||
|
||
// Provider for the DotContentAnalytics instance | ||
export * from './lib/react/components/DotContentAnalyticsProvider'; | ||
export * from './lib/react/hook/useContentAnalytics'; |
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
39 changes: 0 additions & 39 deletions
39
core-web/libs/sdk/analytics/src/lib/react/components/withContentAnalytics.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
core-web/libs/sdk/analytics/src/lib/react/contexts/DotContentAnalyticsContext.spec.tsx
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
2 changes: 1 addition & 1 deletion
2
core-web/libs/sdk/analytics/src/lib/react/contexts/DotContentAnalyticsContext.tsx
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
45 changes: 0 additions & 45 deletions
45
core-web/libs/sdk/analytics/src/lib/react/hook/useAnalyticTracker.ts
This file was deleted.
Oops, something went wrong.
44 changes: 23 additions & 21 deletions
44
core-web/libs/sdk/analytics/src/lib/react/hook/useContentAnalytics.ts
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,31 +1,33 @@ | ||
import { useEffect } from 'react'; | ||
import { useContext } from 'react'; | ||
|
||
import { DotContentAnalytics } from '../../dot-content-analytics'; | ||
import { isInsideEditor } from '../../shared/dot-content-analytics.utils'; | ||
import { DotContentAnalyticsCustomHook } from '../../dotAnalytics/shared/dot-content-analytics.model'; | ||
import { isInsideEditor } from '../../dotAnalytics/shared/dot-content-analytics.utils'; | ||
import DotContentAnalyticsContext from '../contexts/DotContentAnalyticsContext'; | ||
|
||
/** | ||
* Custom hook that handles analytics page view tracking. | ||
* | ||
* @param {DotContentAnalytics | null} instance - The analytics instance used to track page views | ||
* @returns {void} | ||
* @returns {DotContentAnalyticsCustomHook} - The analytics instance used to track page views | ||
* | ||
*/ | ||
export const useContentAnalytics = (instance: DotContentAnalytics | null): void => { | ||
/** | ||
* Tracks page view when component mounts, but only if: | ||
* - We have a valid analytics instance | ||
* - We're in a browser environment | ||
* - We're not inside the editor | ||
*/ | ||
useEffect(() => { | ||
if (!instance || typeof window === 'undefined') { | ||
return; | ||
} | ||
|
||
const insideEditor = isInsideEditor(); | ||
export const useContentAnalytics = (): DotContentAnalyticsCustomHook => { | ||
const instance = useContext(DotContentAnalyticsContext); | ||
const insideEditor = isInsideEditor(); | ||
|
||
if (!insideEditor) { | ||
instance.pageView({ source: 'headless' }); | ||
return { | ||
/** | ||
* Track an event with the analytics instance. | ||
* | ||
* @param {string} eventName - The name of the event to track | ||
* @param {object} payload - Additional data to include with the event | ||
*/ | ||
track: (eventName: string, payload: Record<string, unknown> = {}) => { | ||
if (instance?.track && !insideEditor) { | ||
instance.track(eventName, { | ||
...payload, | ||
timestamp: new Date().toISOString() | ||
}); | ||
} | ||
} | ||
}, [instance]); | ||
}; | ||
}; |
Oops, something went wrong.