---
updatedAt: 2025-05-14T08:28:40.000Z
agentTools:
  projectIndex: https://learn.vtex.com/llms.txt
---

# Gabarito para o passo 'Conhecendo um pouco mais sobre clientes'

<HTMLBlock>{`
<style>
      section#hub-content header h1, section#hub-content header h2 {
        color: #f71963
      }
    
      p {
        line-height: 1.5rem;
      }
    </style>
`}</HTMLBlock>

```typescript analytics.ts
// node/handler/analytics.ts
export async function analytics(ctx: Context, next: () => Promise<any>) {
  const {
    clients: { analytics },
  } = ctx
  ctx.status = 200
  ctx.body = await analytics.getLiveUsers()
  ctx.set('cache-control', 'no-cache')
  await next()
}
```
```typescript analyticsClient.ts
// node/clients/analyticsClient.ts
import { AppClient, InstanceOptions, IOContext } from '@vtex/api'

export default class Analytics extends AppClient {
  constructor(context: IOContext, options?: InstanceOptions) {
    super('vtex.mocked-analytics@0.x', context, options)
  }

  public async getLiveUsers(): Promise<LiveUsersProduct[]> {
    return this.http.get('_v/live-products')
  }
}

export interface LiveUsersProduct {
  slug: string
  liveUsers: number
}
```
```typescript index.ts
// node/clients/index.ts
import { IOClients } from '@vtex/api'
import Analytics from './analyticsClient'

export class Clients extends IOClients {
  public get analytics() {
    return this.getOrSet('analytics', Analytics)
  }
}
```

<HTMLBlock>{`
<div id="back-button">
            <i class="fa fa-angle-left"></i>
            <a id="back-link" href="/docs/course-service-course-step04clients-analytics-lang-en">back</a>
          </div>
`}</HTMLBlock>

<hr/>
<div id="contribute-container">
  <p id="contribute-title"> 
    Help us make this content better!
  </p>
  <p id="contribute-description">
    VTEX IO courses are open source. If you see something wrong, you can open a pull request!
  </p>

  <a id="contribute-button" href="https://github.com/vtex/vtex-courses/edit/master/courses/service-course/steps/04_clients-analytics/answersheet">
    Make a contribution
  </a>

  <p id="contribute-issue">
    or <a href="https://github.com/vtex/vtex-courses/issues/new/choose">open an issue</a>
  </p>

</div>