Skip to content

Commit

Permalink
feat: add parcel count when sending analytics (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogoldman authored Mar 21, 2023
1 parent 691c944 commit 88d3d26
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ export async function main(): Promise<void> {
spinner.succeed(`Content uploaded. ${chalk.underline.bold(sceneUrl)}\n`)

const baseCoords = await dcl.workspace.getBaseCoords()
const parcelCount = await dcl.workspace.getParcelCount()

Analytics.sceneDeploySuccess({
projectHash: dcl.getProjectHash(),
ecs: await dcl.workspace.getSingleProject()!.getEcsPackageVersion(),
parcelCount: parcelCount,
coords: baseCoords
})

Expand All @@ -252,8 +254,6 @@ export async function main(): Promise<void> {
debug('\n' + error.stack)
failWithSpinner('Could not upload content', error)
}

process.exit()
}

function findPointers(sceneJson: any): string[] {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@ export class Project {
}
}

async getSceneParcelCount() {
try {
const sceneFile = await getSceneFile(this.projectWorkingDir)
return sceneFile.scene.parcels.length
} catch (e) {
console.log(error(`Could not open "scene.json" file`))
throw e
}
}

async checkCLIandECSCompatibility() {
const ecsVersion = this.getEcsVersion()
if (ecsVersion === 'unknown') {
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface Workspace {
isSingleProject: () => boolean
hasPortableExperience: () => boolean
getBaseCoords: () => Promise<{ x: number; y: number }>
getParcelCount: () => Promise<number>
addProject: (projectPath: string) => Promise<void>
}

Expand Down Expand Up @@ -117,6 +118,13 @@ export const createWorkspace = ({
: { x: 0, y: 0 }
}

const getParcelCount = async () => {
const firstParcelScene = projects.find(
(project) => project.getInfo().sceneType === sdk.ProjectType.SCENE
)
return firstParcelScene ? await firstParcelScene.getSceneParcelCount() : 0
}

const saveWorkspace = async () => {
if (isSingleProject()) {
throw new Error('Can not save a single project workspace.')
Expand Down Expand Up @@ -165,6 +173,7 @@ export const createWorkspace = ({
isSingleProject,
hasPortableExperience,
getBaseCoords,
getParcelCount,
addProject
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type AnalyticsProject = {
packageVersion: string
}
coords?: { x: number; y: number }
parcelCount?: number
isWorkspace: boolean
}

Expand Down Expand Up @@ -136,7 +137,6 @@ async function track(eventName: string, properties: any = {}) {
}

const shouldTrack = trackStats || eventName === ANONYMOUS_DATA_QUESTION

if (!shouldTrack) {
resolve()
}
Expand Down
52 changes: 25 additions & 27 deletions test/e2e/snapshots/start.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ Generated by [AVA](https://avajs.dev).
localStorage.setItem(toLocalStorageKey, JSON.stringify(storage))␊
}␊
}␊
␊
␊
if (toLocalStorageKey !== ''){␊
storage = JSON.parse(localStorage.getItem(toLocalStorageKey) || '{}');␊
}␊
Expand Down Expand Up @@ -662,45 +662,43 @@ Generated by [AVA](https://avajs.dev).
containerElement.style.display = 'block'␊
}␊
␊
async function getRendererBaseUrl() {␊
async function getExplorerBaseUrl() {␊
const qs = new URLSearchParams(document.location.search)␊
␊
if (qs.has('renderer')) {␊
return qs.get('renderer')␊
if (qs.has('explorer')) {␊
return qs.get('explorer')␊
}␊
␊
if (qs.has('renderer-branch')) {␊
return \`https://renderer-artifacts.decentraland.org/branch/${qs.get('renderer-branch')}\`␊
if (qs.has('explorer-branch')) {␊
return \`https://renderer-artifacts.decentraland.org/branch/${qs.get('explorer-branch')}\`␊
}␊
␊
if (qs.has('renderer-version')) {␊
return \`https://cdn.decentraland.org/@dcl/unity-renderer/${qs.get('renderer-version')}\`␊
␊
if (qs.has('explorer-version')) {␊
return \`https://cdn.decentraland.org/@dcl/explorer/${qs.get('explorer-version')}\`␊
}␊
␊
return new URL('@/artifacts/unity-renderer', location.toString()).toString()␊
// the CLI tool binds @/explorer to a static server serving the contents of␊
// the @dcl/explorer package, it has the same behavior as the CDNs listed␊
// above␊
return new URL('@/explorer', location.toString()).toString()␊
}␊
␊
async function getKernelBaseUrl() {␊
async function getRendererBaseUrl() {␊
const qs = new URLSearchParams(document.location.search)␊
␊
if (qs.has('kernel-branch')) {␊
return \`https://sdk-team-cdn.decentraland.org/@dcl/kernel/branch/${qs.get('kernel-branch')}\`␊
}␊
␊
if (qs.has('kernel-version')) {␊
return \`https://cdn.decentraland.org/@dcl/kernel/${qs.get('kernel-version')}\`␊
if (qs.has('renderer-branch')) {␊
return \`https://renderer-artifacts.decentraland.org/branch/${qs.get('renderer-branch')}\`␊
}␊
␊
if (qs.has('kernel')) {␊
return qs.get('kernel')␊
if (qs.has('renderer-version')) {␊
return \`https://cdn.decentraland.org/@dcl/explorer/${qs.get('renderer-version')}\`␊
}␊
␊
return new URL(\`@/artifacts\`, location.toString()).toString()␊
}␊
␊
async function initKernel() {␊
const kernelBaseUrl = await getKernelBaseUrl()␊
const kernelScript = (new URL('index.js', \`${kernelBaseUrl}/\`)).toString()␊
const baseUrl = await getExplorerBaseUrl()␊
const rendererBaseUrl = await getRendererBaseUrl() || baseUrl␊
const kernelScript = (new URL('index.js', \`${baseUrl}/\`)).toString()␊
␊
await injectScript(kernelScript)␊
␊
Expand All @@ -711,15 +709,15 @@ Generated by [AVA](https://avajs.dev).
␊
const kernel = await DecentralandKernel.initKernel({␊
kernelOptions: {␊
baseUrl: kernelBaseUrl,␊
baseUrl,␊
previewMode: true,␊
persistentStorage: mockStorage({␊
toLocalStorageKey: getPlayerSessionKey()␊
})␊
},␊
rendererOptions: {␊
container,␊
baseUrl: await getRendererBaseUrl()␊
baseUrl: rendererBaseUrl␊
}␊
})␊
␊
Expand Down Expand Up @@ -798,7 +796,7 @@ Generated by [AVA](https://avajs.dev).
if (!window.electron || !window.electron.ipcRenderer) {␊
return␊
}␊
␊
␊
const ipcRenderer = window.electron.ipcRenderer␊
␊
ipcRenderer.on('downloadState', (event, payload) => {␊
Expand All @@ -820,7 +818,7 @@ Generated by [AVA](https://avajs.dev).
␊
ipcRenderer.send('checkVersion')␊
}␊
␊
␊
async function injectScript(url) {␊
return new Promise( (resolve, reject) => {␊
const theScript = document.createElement('script')␊
Expand Down
Binary file modified test/e2e/snapshots/start.test.ts.snap
Binary file not shown.

0 comments on commit 88d3d26

Please sign in to comment.