Merge pull request #3303 from specklesystems/dim/viewer-receive-events

Adds viewer receive events
This commit is contained in:
Dimitrie Stefanescu
2024-10-16 14:47:46 +01:00
committed by GitHub
@@ -52,6 +52,7 @@ import { setupDebugMode } from '~~/lib/viewer/composables/setup/dev'
import type { Reference } from '@apollo/client'
import type { Modifier } from '@apollo/client/cache'
import { useEmbed } from '~/lib/viewer/composables/setup/embed'
import { useMixpanel } from '~~/lib/core/composables/mp'
function useViewerIsBusyEventHandler() {
const state = useInjectedViewerState()
@@ -154,6 +155,35 @@ function useViewerObjectAutoLoading() {
})
}
/**
* Here we make the viewer pretend it's a connector and send out receive events. Note, this is important for us to track to be able to get a picture of how much data is consumed
* in our viewer.
*/
function useViewerReceiveTracking() {
//
const {
resources: {
response: { modelsAndVersionIds }
}
} = useInjectedViewerState()
const mixpanel = useMixpanel()
const { userId } = useActiveUser()
const receivedVersions = new Set<string>()
watch(modelsAndVersionIds, (newVal) => {
for (const { model, versionId } of newVal) {
if (receivedVersions.has(versionId)) {
continue
}
receivedVersions.add(versionId)
mixpanel.track('Receive', {
hostApp: 'viewer',
sourceHostApp: model.loadedVersion.items[0].sourceApplication,
isMultiplayer: model.loadedVersion.items[0].authorUser?.id !== userId.value
})
}
})
}
/**
* Listening to model/version updates through subscriptions and making various
* cache updates so that we don't need to always refetch queries
@@ -791,6 +821,7 @@ function useDisableZoomOnEmbed() {
export function useViewerPostSetup() {
if (import.meta.server) return
useViewerObjectAutoLoading()
useViewerReceiveTracking()
useViewerSelectionEventHandler()
useViewerIsBusyEventHandler()
useViewerSubscriptionEventTracker()