Add more github analytics (#6506)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-09-10 09:40:15 +04:00 committed by GitHub
parent 9a9d7195bf
commit 87b8e59969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 76 additions and 7 deletions

View File

@ -29,6 +29,7 @@ import {
type DocAttributeRule,
type DocCreateExtension,
type DocCreateFunction,
type DocCreateAnalyticsPropsFunction,
type DocRules,
type FileOrBlob,
type FilePreviewExtension,
@ -42,7 +43,14 @@ import presentation from './plugin'
export { presentationId } from '@hcengineering/presentation/src/plugin'
export { default } from './plugin'
export type { CreateExtensionKind, DocCreateExtension, DocCreateFunction, ObjectSearchCategory, ObjectSearchFactory }
export type {
CreateExtensionKind,
DocCreateExtension,
DocCreateFunction,
ObjectSearchCategory,
ObjectSearchFactory,
DocCreateAnalyticsPropsFunction
}
@Model(presentation.class.ObjectSearchCategory, core.class.Doc, DOMAIN_MODEL)
export class TObjectSearchCategory extends TDoc implements ObjectSearchCategory {
@ -76,6 +84,7 @@ export class TDocCreateExtension extends TDoc implements DocCreateExtension {
components!: Record<CreateExtensionKind, AnyComponent>
apply!: Resource<DocCreateFunction>
getAnalyticsProps?: Resource<(doc: Doc) => Record<string, string>>
}
@Model(presentation.class.DocRules, core.class.Doc, DOMAIN_MODEL)

View File

@ -65,6 +65,20 @@ export class DocCreateExtensionManager {
}
}
async getAnalyticsProps (space: Space, data: DocData<Doc>): Promise<Record<string, string>> {
let result: Record<string, string> = {}
for (const e of this._extensions) {
if (e.getAnalyticsProps === undefined) continue
const state = get(this.getState(e._id))
const fn = await getResource(e.getAnalyticsProps)
const props = fn?.(space, data, state)
result = { ...result, ...props }
}
return result
}
close (): void {
this.query.unsubscribe()
}

View File

@ -106,6 +106,12 @@ export type DocCreateFunction = (
phase: DocCreatePhase
) => Promise<void>
export type DocCreateAnalyticsPropsFunction = (
space: Space,
document: DocData<Doc>,
extraData: Record<string, any>
) => Record<string, any>
/**
* @public
*/
@ -123,6 +129,7 @@ export interface DocCreateExtension extends Doc {
components: Partial<Record<CreateExtensionKind, AnyComponent>>
apply: Resource<DocCreateFunction>
getAnalyticsProps?: Resource<DocCreateAnalyticsPropsFunction>
}
export interface DocAttributeRule {

View File

@ -575,10 +575,12 @@
descriptionBox?.removeDraft(false)
isAssigneeTouched = false
const d1 = Date.now()
const analyticsProps = await docCreateManager.getAnalyticsProps(currentProject, value)
Analytics.handleEvent(TrackerEvents.IssueCreated, {
ok: true,
id: value.identifier,
project: currentProject.identifier
project: currentProject.identifier,
...analyticsProps
})
console.log('createIssue measure', result, Date.now() - d1)
} catch (err: any) {

View File

@ -53,7 +53,7 @@
return
}
Analytics.handleEvent('Connect project to github')
Analytics.handleEvent('github.project.connected', { project: projectInst.identifier, repository: repository._id })
if (!client.getHierarchy().hasMixin(projectInst, github.mixin.GithubProject)) {
// We need to add GithubProject mixin

View File

@ -20,6 +20,8 @@
showPopup
} from '@hcengineering/ui'
import { ObjectPresenter } from '@hcengineering/view-resources'
import { Analytics } from '@hcengineering/analytics'
import github from '../plugin'
import ConnectProject from './ConnectProject.svelte'
import { githubLanguageColors } from './languageColors'
@ -45,6 +47,10 @@
await client.update(prj, {
$pull: { repositories: repository._id }
})
Analytics.handleEvent('github.project.disconnected', {
project: prj.identifier,
repository: repository._id
})
// // We need to delete all issues related to repository
// const ops = client.apply('cleanup:' + repository._id)
// const issuesQuery = await client.findAll(

View File

@ -4,7 +4,12 @@
import { type Data, type Ref, type Space, type TxOperations } from '@hcengineering/core'
import { type Resources } from '@hcengineering/platform'
import { getClient, type DocCreateFunction, type DocCreatePhase } from '@hcengineering/presentation'
import {
getClient,
type DocCreateFunction,
type DocCreatePhase,
type DocCreateAnalyticsPropsFunction
} from '@hcengineering/presentation'
import tracker, { type Issue } from '@hcengineering/tracker'
import { type GithubIntegrationRepository } from '@hcengineering/github'
import AuthenticationCheck from './components/AuthenticationCheck.svelte'
@ -51,6 +56,25 @@ async function updateIssue (
}
}
function getCreateIssueAnalyticsProps (
space: Space,
issue: Data<Issue>,
settings: Record<string, any>
): Record<string, any> {
const hierarchy = getClient().getHierarchy()
if (hierarchy.hasMixin(space, github.mixin.GithubProject)) {
const repository = settings.repository as Ref<GithubIntegrationRepository>
if (repository == null) return {}
return {
github: true,
githubRepository: repository
}
}
return {}
}
export default async (): Promise<Resources> => ({
component: {
Connect,
@ -85,6 +109,7 @@ export default async (): Promise<Resources> => ({
const client = getClient()
return spaces.some((it) => client.getHierarchy().hasMixin(it, github.mixin.GithubProject))
},
UpdateIssue: updateIssue as DocCreateFunction
UpdateIssue: updateIssue as DocCreateFunction,
GetCreateIssueAnalyticsProps: getCreateIssueAnalyticsProps as DocCreateAnalyticsPropsFunction
}
})

View File

@ -655,6 +655,7 @@ export function createModel (builder: Builder): void {
builder.createDoc(presentation.class.DocCreateExtension, core.space.Model, {
ofClass: tracker.class.Issue,
apply: github.functions.UpdateIssue,
getAnalyticsProps: github.functions.GetCreateIssueAnalyticsProps,
components: {
createButton: github.component.GithubIssueInfoHeader
}

View File

@ -8,7 +8,11 @@ import github from '@hcengineering/github-resources/src/plugin'
import { type ChatMessageViewlet } from '@hcengineering/chunter'
import { type Doc, type Ref, type Space } from '@hcengineering/core'
import { type DocCreateFunction, type ObjectSearchCategory } from '@hcengineering/model-presentation'
import {
type DocCreateFunction,
type ObjectSearchCategory,
type DocCreateAnalyticsPropsFunction
} from '@hcengineering/model-presentation'
import { type NotificationGroup } from '@hcengineering/notification'
import type { AnyComponent } from '@hcengineering/ui'
import { type ActionCategory, type Viewlet } from '@hcengineering/view'
@ -55,7 +59,8 @@ export default mergeIds(githubId, github, {
},
functions: {
ShowForRepositoryOnly: '' as Resource<(spaces: Space[]) => Promise<boolean>>,
UpdateIssue: '' as Resource<DocCreateFunction>
UpdateIssue: '' as Resource<DocCreateFunction>,
GetCreateIssueAnalyticsProps: '' as Resource<DocCreateAnalyticsPropsFunction>
},
ids: {
AssigneeNotification: '' as Ref<Doc>,