A reusable React hook for recording analytics across EPIC applications and logging them to EPIC.centre.
Add to your application's package.json:
{
"dependencies": {
"@epic/centre-analytics": "git+https://github.com/YOUR_USERNAME/centre-analytics.git#main"
}
}Then run:
npm installimport { trackAnalytics } from '@epic/centre-analytics';
function RouterProviderWithAuthContext() {
const { isAuthenticated } = useAuth();
trackAnalytics({
appName: 'epic_submit',
centreApiUrl: 'https://centre-api.example.com',
});
// ... rest of component
}trackAnalytics({
appName: 'epic_submit',
centreApiUrl: process.env.VITE_CENTRE_API_URL,
enabled: isAuthenticated,
onSuccess: () => {
console.log('Analytics recorded successfully');
},
onError: (error) => {
console.error('Analytics recording failed:', error);
},
});appName(required): The application name ('epic_submit','condition_repository','epic_compliance','epic_engage','epic_public')centreApiUrl(required): Base URL of EPIC.centre APIenabled(optional): Enable/disable analytics recording (default:true)onSuccess(optional): Callback on successful recordingonError(optional): Callback on recording error
isRecording: Boolean indicating if analytics recording is in progresserror: Error object if recording failed
- Automatically extracts user info from OIDC token
- Maps application name to app_id
- Debounces analytics recording (max once per 5 seconds per session)
- Silent error handling (won't break your app)
- TypeScript support
Add to your application's environment configuration:
VITE_CENTRE_API_URL=https://centre-api.example.comepic_submit- EPIC.submitcondition_repository- EPIC.conditionsepic_compliance- EPIC.complianceepic_engage- epic-engageepic_public- epic-public