Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oppdater amplitude #256

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
deploy-til-dev:
name: Deploy til dev-gcp
needs: bygg-og-push-docker-image
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/fjern-janzz-fra-minne-dersom-onToggle-blir-kalt-uten-verdi'
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/master' || github.ref == 'refs/heads/amplitude'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
184 changes: 81 additions & 103 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
},
"dependencies": {
"@amplitude/analytics-browser": "^2.11.9",
"@grafana/faro-web-sdk": "1.3.9",
"@grafana/faro-web-tracing": "1.3.9",
"@navikt/ds-css": "6.1.0",
Expand All @@ -42,7 +43,6 @@
"@tiptap/extension-underline": "^2.5.5",
"@tiptap/pm": "^2.5.5",
"@tiptap/react": "^2.5.5",
"amplitude-js": "^8.21.9",
"classnames": "2.5.1",
"deep-equal": "2.2.3",
"history": "^5.3.0",
Expand All @@ -68,7 +68,6 @@
"@testing-library/jest-dom": "^6.1.0",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/amplitude-js": "^8.16.2",
"@types/loadjs": "^4.0.0",
"@types/node": "^20.12.7",
"@types/react": "^18.2.14",
Expand Down
47 changes: 23 additions & 24 deletions src/felles/amplitude.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import amplitudeJs, { AmplitudeClient } from 'amplitude-js';
import * as amplitude from '@amplitude/analytics-browser';
import { Types } from '@amplitude/analytics-browser';
import { Miljø, getMiljø } from './miljø';

export enum AmplitudeEvent {
Expand All @@ -14,47 +15,45 @@ const getApiKey = () => {

export const setNavKontorForAmplitude = (navKontor: string) => {
if (import.meta.env.PROD) {
client.setUserProperties({
navKontor,
});
const nyttIdentitentsObjekt = new amplitude.Identify();
nyttIdentitentsObjekt.set('navKontor', navKontor);
client()?.identify(nyttIdentitentsObjekt);
}
};

export const sendEvent = (område: string, hendelse: string, data?: object) => {
if (import.meta.env.PROD) {
client.logEvent(['#rekrutteringsbistand', område, hendelse].join('-'), data);
client()?.logEvent(['#rekrutteringsbistand', område, hendelse].join('-'), data);
}
};

export const sendGenerellEvent = (
event: AmplitudeEvent | string,
properties: Record<string, any>
): Promise<void> | undefined => {
) => {
if (import.meta.env.PROD) {
const eventProperties = {
app: 'rekrutteringsbistand',
...properties,
};

return new Promise((resolve, reject) => {
client.logEvent(
event,
eventProperties,
() => resolve(),
() => reject()
);
});
client()?.logEvent(event, eventProperties);
}
};

const client: AmplitudeClient = amplitudeJs.getInstance();

if (import.meta.env.PROD) {
client.init(getApiKey(), '', {
apiEndpoint: 'amplitude.nav.no/collect',
saveEvents: false,
includeUtm: true,
batchEvents: false,
includeReferrer: false,
export const client = (): Pick<Types.BrowserClient, 'logEvent' | 'identify'> | null => {
amplitude.init(getApiKey(), undefined, {
serverUrl: 'https://amplitude.nav.no/collect',
useBatch: false,
autocapture: {
attribution: true,
fileDownloads: false,
formInteractions: false,
pageViews: true,
sessions: true,
elementInteractions: false,
},
});
}

return amplitude;
};
Loading
Loading