Skip to content

Commit

Permalink
MAN-256 fix applicationinsights dependency import paths
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-mills committed Jan 10, 2025
1 parent cc17c1d commit 907e629
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
40 changes: 23 additions & 17 deletions assets/js/appInsights.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
import { ClickAnalyticsPlugin } from '@microsoft/applicationinsights-clickanalytics-js'
/* eslint-disable import/no-unresolved */
/* eslint-disable import/extensions */
/* eslint-disable no-param-reassign */
/* eslint-disable no-unused-expressions */
/* eslint-disable no-console */

import * as ApplicationInsights from './es5/applicationinsights-web.min.js'
import * as ClickAnalyticsPlugin from './es5/applicationinsights-clickanalytics-js.min.js'

document.initialiseTelemetry = (
applicationInsightsConnectionString,
applicationInsightsRoleName,
coreTelemetryData,
) => {
if (!Boolean(applicationInsightsConnectionString)) {
if (!applicationInsightsConnectionString) {
console.log('AppInsights not configured')
return
}
Expand All @@ -30,19 +36,19 @@ document.initialiseTelemetry = (
autoTrackPageVisitTime: true,
extensions: [clickPluginInstance],
extensionConfig: {
[clickPluginInstance.identifier]: clickPluginConfig
[clickPluginInstance.identifier]: clickPluginConfig,
},
}
},
})

const telemetryInitializer = (envelope) => {
envelope.tags["ai.cloud.role"] = applicationInsightsRoleName
envelope.data['ASSESSMENT_ID'] = coreTelemetryData.assessmentId
envelope.data['ASSESSMENT_VERSION'] = coreTelemetryData.assessmentVersion.toString()
envelope.data['SECTION_CODE'] = coreTelemetryData.section
envelope.data['USER_ID'] = coreTelemetryData.user
envelope.data['HANDOVER_SESSION_ID'] = coreTelemetryData.handoverSessionId
envelope.data['FORM_VERSION'] = coreTelemetryData.formVersion.split(':')[1] || 'Unknown'
const telemetryInitializer = envelope => {
envelope.tags['ai.cloud.role'] = applicationInsightsRoleName
envelope.data.ASSESSMENT_ID = coreTelemetryData.assessmentId
envelope.data.ASSESSMENT_VERSION = coreTelemetryData.assessmentVersion.toString()
envelope.data.SECTION_CODE = coreTelemetryData.section
envelope.data.USER_ID = coreTelemetryData.user
envelope.data.HANDOVER_SESSION_ID = coreTelemetryData.handoverSessionId
envelope.data.FORM_VERSION = coreTelemetryData.formVersion.split(':')[1] || 'Unknown'
}

appInsights.loadAppInsights()
Expand All @@ -58,11 +64,11 @@ document.initialiseTelemetry = (
trackEvent('AUTOSAVED')
})

document.addEventListener('copy', (e) => {
['textarea', 'text'].includes(e.target.type) && trackEvent('USER_COPY', { QUESTION_CODE: e.target.name })
document.addEventListener('copy', e => {
;['textarea', 'text'].includes(e.target.type) && trackEvent('USER_COPY', { QUESTION_CODE: e.target.name })
})

document.addEventListener('paste', (e) => {
['textarea', 'text'].includes(e.target.type) && trackEvent('USER_PASTE', { QUESTION_CODE: e.target.name })
document.addEventListener('paste', e => {
;['textarea', 'text'].includes(e.target.type) && trackEvent('USER_PASTE', { QUESTION_CODE: e.target.name })
})
}
4 changes: 2 additions & 2 deletions server/middleware/setUpStaticResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export default function setUpStaticResources(): Router {
'/node_modules/govuk-frontend/dist',
'/node_modules/@ministryofjustice/frontend/moj/assets',
'/node_modules/@ministryofjustice/frontend',
'/node_modules/@microsoft/applicationinsights-web/dist/es5',
'/node_modules/@microsoft/applicationinsights-clickanalytics-js/dist/es5',
'/node_modules/@microsoft/applicationinsights-web/dist',
'/node_modules/@microsoft/applicationinsights-clickanalytics-js/dist',
).forEach(dir => {
router.use('/assets', express.static(path.join(process.cwd(), dir), staticResourcesConfig))
})
Expand Down

0 comments on commit 907e629

Please sign in to comment.