Skip to content

Commit

Permalink
chore: Creator Hub analytics (#1023)
Browse files Browse the repository at this point in the history
* chore: send project id and app id on track events

* chore: add analytics source to scene.json

* chore: fix test
  • Loading branch information
cazala authored Oct 29, 2024
1 parent 065d563 commit 8a0f3dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ComponentDefinition, CompositeDefinition, DeepReadonlyObject, Entity } from '@dcl/ecs'
import { ReadWriteByteBuffer } from '@dcl/ecs/dist/serialization/ByteBuffer'
import { dataCompare } from '@dcl/ecs/dist/systems/crdt/utils'
import { Scene } from '@dcl/schemas'

import { EditorComponentsTypes, SceneAgeRating, SceneCategory, SceneComponent } from '../../../sdk/components'
import { Scene } from '@dcl/schemas'
import { getConfig } from '../../../logic/config'

export function isEqual(component: ComponentDefinition<unknown>, prevValue: unknown, newValue: unknown) {
if (prevValue === newValue || (!prevValue && !newValue)) return true
Expand Down Expand Up @@ -40,6 +41,7 @@ export function fromSceneComponent(value: DeepReadonlyObject<EditorComponentsTyp
const sanitizedTag = tag.trim()
if (sanitizedTag && !tags.includes(sanitizedTag)) tags.push(sanitizedTag)
}
const config = getConfig()
const scene: Partial<SceneWithRating> = {
display: {
title: value.name || '',
Expand Down Expand Up @@ -74,6 +76,14 @@ export function fromSceneComponent(value: DeepReadonlyObject<EditorComponentsTyp
rating: value.ageRating
}

if (config.segmentAppId && config.projectId) {
// add analytics source
scene.source = {
origin: config.segmentAppId,
projectId: config.projectId
}
}

return scene
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@dcl/sdk-commands/src/components/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ export async function createAnalyticsComponent(components: Pick<CliComponents, '
isCI: isCI(),
isEditor: isEditor(),
devId: anonId,
projectId: process.env.ANALYTICS_PROJECT_ID || null,
appId: process.env.ANALYTICS_APP_ID || null,
ecs: {
ecsVersion: 'ecs7',
packageVersion: sdkVersion
Expand Down
2 changes: 2 additions & 0 deletions test/sdk-commands/utils/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ describe('Analytics Component', () => {
isCI: isCI(),
isEditor: false,
devId: 'fb3f84b2-4ddc-4a7e-96bf-1e8992c294dd',
appId: null,
projectId: null,
ecs: {
ecsVersion: 'ecs7',
packageVersion: 'unknown'
Expand Down

0 comments on commit 8a0f3dc

Please sign in to comment.