Skip to content

Commit fe02edb

Browse files
committed
First cut at analytics
Signed-off-by: Heiko W. Rupp <[email protected]>
1 parent 7a15095 commit fe02edb

File tree

13 files changed

+178
-0
lines changed

13 files changed

+178
-0
lines changed

.env.github.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ IL_ENABLE_DEV_MODE=true #Enable this option if you want to enable UI features th
2323
NEXT_PUBLIC_EXPERIMENTAL_FEATURES=false
2424

2525
SLACK_WEBHOOK_URL=
26+
27+
# Analtyics setup
28+
# UMAMI_KEY: 'umami-key'
29+
# UMAMI_HOST_URL: 'http://umami-host:3000'
30+
# SEGMENT_KEY: 'segment-key'
31+
# Next needs to be in one line
32+
# SEGMENT_INTEGRATIONS: '{"Segment.io": {"apiHost": "some.host.com/connections/api/v1","protocol": "https"}}'
33+
# SEGMENT_CDN: 'https://some.host.com/connections/cdn'

.env.native.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ NEXT_PUBLIC_EXPERIMENTAL_FEATURES=false
1515
# IL_FILE_CONVERSION_SERVICE=http://localhost:5001 # Uncomment and fill in the http://host:port if the docling conversion service is running.
1616
# NEXT_PUBLIC_API_SERVER=http://localhost:8080 # Uncomment and point to the URL the api-server is running on. Native mode only and needs to be running on the same host as the UI.
1717
# NEXT_PUBLIC_MODEL_SERVER_URL=http://x.x.x.x # Used for model chat evaluation vLLM instances. Currently, server side rendering is not supported so the client must have access to this address for model chat evaluation to function in the UI. Currently ports, 8000 & 8001 are hardcoded and why it is not an option to set.
18+
19+
20+
# Analtyics setup
21+
# UMAMI_KEY: 'umami-key'
22+
# UMAMI_HOST_URL: 'http://umami-host:3000'
23+
# SEGMENT_KEY: 'segment-key'
24+
# Next needs to be in one line
25+
# SEGMENT_INTEGRATIONS: '{"Segment.io": {"apiHost": "some.host.com/connections/api/v1","protocol": "https"}}'
26+
# SEGMENT_CDN: 'https://some.host.com/connections/cdn'

package-lock.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export async function GET() {
6+
const uiConfig = {
7+
umamiKey: process.env.UMAMI_KEY || '',
8+
umamiHostUrl: process.env.UMAMI_HOST_URL || '',
9+
segmentKey: process.env.SEGMENT_KEY || '',
10+
segmentCdn: process.env.SEGMENT_CDN || '',
11+
segmentIntegrations: {}
12+
} ;
13+
14+
const tmp = process.env.SEGMENT_INTEGRATIONS;
15+
if (tmp) {
16+
uiConfig.segmentIntegrations = JSON.parse(tmp);
17+
}
18+
19+
return NextResponse.json(uiConfig);
20+
}

src/app/playground/chat/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const ChatPage: React.FC = () => {
3636
variant="link"
3737
isInline
3838
onClick={(e) => {
39+
window.analytics.trackSingleItem('Chat Cleared', {});
3940
e.preventDefault();
4041
router.push('/playground/endpoints');
4142
}}

src/app/playground/endpoints/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const EndpointsPage: React.FC = () => {
6666
};
6767

6868
const handleSaveEndpoint = () => {
69+
window.analytics.trackSingleItem(currentEndpoint ? 'Model Endpoint edited' : 'Model Endpoint added', {})
6970
const updatedUrl = removeTrailingSlash(url);
7071
if (currentEndpoint) {
7172
const updatedEndpoint: ExtendedEndpoint = {

src/components/AppLayout.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
import { BarsIcon } from '@patternfly/react-icons';
3333
import ThemePreference from '@/components/ThemePreference/ThemePreference';
3434
import '../styles/globals.scss';
35+
import { initAnalytics } from '@/components/analytics/initAnalytics';
3536

3637
interface IAppLayout {
3738
children: React.ReactNode;
@@ -61,6 +62,28 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children, className })
6162
fetchExperimentalFeature();
6263
}, []);
6364

65+
React.useEffect(() => {
66+
console.log("Get analytics effect " + window.analytics);
67+
if (!window.analytics) {
68+
initAnalytics();
69+
}
70+
}, []);
71+
72+
React.useEffect(() => {
73+
if (window.analytics) {
74+
window.analytics.trackPageView(pathname);
75+
}
76+
77+
}, [pathname]);
78+
79+
React.useEffect(() => {
80+
console.log(("Identify effect " + session?.user) )
81+
if (window.analytics) {
82+
// TODO we may potentially want to hash this. Also different code per target install?
83+
window.analytics.identify(session?.user?.name ? session.user.name : '-unknown-user-name ');
84+
}
85+
},[session?.user?.name,session?.user]);
86+
6487
React.useEffect(() => {
6588
if (status === 'loading') return; // Do nothing while loading
6689
if (!session && pathname !== '/login') {

src/components/Contribute/ContributionWizard/ContributionWizard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ export const ContributionWizard: React.FunctionComponent<Props> = ({
141141

142142
const autoFillForm = (): void => {
143143
setFormData(isSkillContribution ? { ...autoFillSkillsFields } : { ...autoFillKnowledgeFields });
144+
window.analytics.trackSingleItem('AutoFill Clicked', {isSkillContribution});
144145
};
145146

146147
const handleCancel = () => {
148+
window.analytics.trackSingleItem('Contribution Cancelled', {isSkillContribution});
147149
router.push('/dashboard');
148150
};
149151

src/components/Contribute/Knowledge/KnowledgeSeedExamples/KnowledgeSeedExamples.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ const KnowledgeSeedExamples: React.FC<Props> = ({ isGithubMode, filesToUpload, u
102102
seedExample.immutable = false;
103103
seedExample.isExpanded = true;
104104
onUpdateSeedExamples([...seedExamples, seedExample]);
105+
window.analytics.trackSingleItem("Added Seed", {isSkillContribution: false});
105106
};
106107

107108
const deleteSeedExample = (seedExampleIndex: number): void => {
108109
onUpdateSeedExamples(seedExamples.filter((_, index: number) => index !== seedExampleIndex));
110+
window.analytics.trackSingleItem("Deleted Seed", {isSkillContribution: false});
109111
};
110112

111113
return (

src/components/Contribute/Knowledge/KnowledgeWizard/KnowledgeWizard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export const KnowledgeWizard: React.FunctionComponent<KnowledgeFormProps> = ({ k
269269
return isDocUploaded;
270270
}
271271

272+
window.analytics.trackSingleItem("Knowledge Contribution Submitted", {}); // TODO add data
272273
if (knowledgeEditFormData) {
273274
const result = isGithubMode
274275
? await updateGithubKnowledgeData(session, knowledgeFormData, knowledgeEditFormData, updateActionGroupAlertContent)
@@ -292,6 +293,7 @@ export const KnowledgeWizard: React.FunctionComponent<KnowledgeFormProps> = ({ k
292293

293294
const onYamlUploadKnowledgeFillForm = (data: KnowledgeYamlData): void => {
294295
setKnowledgeFormData(addYamlUploadKnowledge(knowledgeFormData, data));
296+
window.analytics.trackSingleItem('Knowledge Yaml uploaded', {});
295297
updateActionGroupAlertContent({
296298
title: 'YAML Uploaded Successfully',
297299
message: 'Your knowledge form has been populated based on the uploaded YAML file.',

0 commit comments

Comments
 (0)