-
Notifications
You must be signed in to change notification settings - Fork 239
feat(ui): adicionar serviço de telemetria opt-in para rastreamento de uso de componentes #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,162 @@ | ||||||||||||||||||
| [comment]: # (@label Telemetria) | ||||||||||||||||||
| [comment]: # (@link guides/telemetry) | ||||||||||||||||||
|
|
||||||||||||||||||
| ## Telemetria do PO UI | ||||||||||||||||||
|
|
||||||||||||||||||
| O PO UI oferece um serviço de telemetria **opt-in** que permite coletar dados anônimos sobre o uso dos componentes da biblioteca. Esses dados ajudam a equipe de desenvolvimento a entender quais componentes são mais utilizados, priorizar melhorias e corrigir problemas. | ||||||||||||||||||
|
|
||||||||||||||||||
| ### O que é coletado | ||||||||||||||||||
|
|
||||||||||||||||||
| Os eventos de telemetria contêm apenas as seguintes informações: | ||||||||||||||||||
|
|
||||||||||||||||||
| | Campo | Descrição | | ||||||||||||||||||
| |---|---| | ||||||||||||||||||
| | `componentName` | Nome do componente utilizado (ex: `po-button`, `po-table`) | | ||||||||||||||||||
| | `libraryVersion` | Versão da biblioteca `@po-ui/ng-components` | | ||||||||||||||||||
| | `angularVersion` | Versão do Angular utilizada na aplicação | | ||||||||||||||||||
| | `timestamp` | Data e hora do evento em formato ISO 8601 | | ||||||||||||||||||
| | `sessionId` | Identificador aleatório da sessão do navegador | | ||||||||||||||||||
|
|
||||||||||||||||||
| > **Nenhum dado pessoal, de negócio ou sensível é coletado.** Não são rastreados dados de formulário, interações do usuário ou informações de identificação pessoal. | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Como habilitar | ||||||||||||||||||
|
|
||||||||||||||||||
| A telemetria está **desabilitada por padrão**. Para habilitá-la, utilize o `PoTelemetryModule.forRoot()` na configuração do seu módulo ou aplicação: | ||||||||||||||||||
|
|
||||||||||||||||||
| **Abordagem com NgModule:** | ||||||||||||||||||
|
|
||||||||||||||||||
| ```typescript | ||||||||||||||||||
| import { PoTelemetryModule } from '@po-ui/ng-components'; | ||||||||||||||||||
|
|
||||||||||||||||||
| @NgModule({ | ||||||||||||||||||
| imports: [ | ||||||||||||||||||
| PoModule, | ||||||||||||||||||
| PoTelemetryModule.forRoot({ | ||||||||||||||||||
| enabled: true, | ||||||||||||||||||
| endpointUrl: 'https://my-telemetry-api.example.com/events', | ||||||||||||||||||
| showConsentDialog: true | ||||||||||||||||||
| }) | ||||||||||||||||||
| ] | ||||||||||||||||||
| }) | ||||||||||||||||||
| export class AppModule {} | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| **Abordagem Standalone:** | ||||||||||||||||||
|
|
||||||||||||||||||
| ```typescript | ||||||||||||||||||
| import { importProvidersFrom } from '@angular/core'; | ||||||||||||||||||
| import { PoTelemetryModule } from '@po-ui/ng-components'; | ||||||||||||||||||
|
|
||||||||||||||||||
| bootstrapApplication(AppComponent, { | ||||||||||||||||||
| providers: [ | ||||||||||||||||||
| importProvidersFrom(PoTelemetryModule.forRoot({ | ||||||||||||||||||
| enabled: true, | ||||||||||||||||||
| endpointUrl: 'https://my-telemetry-api.example.com/events', | ||||||||||||||||||
| showConsentDialog: true | ||||||||||||||||||
| })) | ||||||||||||||||||
| ] | ||||||||||||||||||
| }); | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Configurações disponíveis | ||||||||||||||||||
|
|
||||||||||||||||||
| | Propriedade | Tipo | Padrão | Descrição | | ||||||||||||||||||
| |---|---|---|---| | ||||||||||||||||||
| | `enabled` | `boolean` | `false` | Habilita ou desabilita a coleta de telemetria | | ||||||||||||||||||
| | `endpointUrl` | `string` | — | URL do endpoint que receberá os eventos | | ||||||||||||||||||
|
Comment on lines
+63
to
+66
|
||||||||||||||||||
| | `consentStorageKey` | `string` | `po-telemetry-consent` | Chave no `localStorage` para armazenar o consentimento | | ||||||||||||||||||
| | `batchIntervalMs` | `number` | `30000` | Intervalo em milissegundos para envio em batch | | ||||||||||||||||||
| | `showConsentDialog` | `boolean` | `true` | Exibe diálogo de consentimento na primeira vez | | ||||||||||||||||||
| | `consentDialogLiterals` | `object` | — | Literais customizadas para o diálogo de consentimento | | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Como o consentimento funciona | ||||||||||||||||||
|
|
||||||||||||||||||
| O serviço de telemetria implementa um mecanismo de consentimento em duas camadas: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. **Configuração do desenvolvedor**: A telemetria só é ativada quando `enabled: true` é definido na configuração. | ||||||||||||||||||
| 2. **Consentimento do usuário final**: Mesmo com a telemetria habilitada, os dados só são coletados após o consentimento explícito do usuário. | ||||||||||||||||||
|
|
||||||||||||||||||
| O fluxo de consentimento funciona da seguinte forma: | ||||||||||||||||||
|
|
||||||||||||||||||
| - Ao inicializar, o serviço verifica o `localStorage` pela chave configurada (`po-telemetry-consent` por padrão). | ||||||||||||||||||
| - Se não houver valor armazenado e `showConsentDialog` estiver habilitado, um diálogo de confirmação é exibido ao usuário utilizando o `PoDialogService`. | ||||||||||||||||||
| - Se o usuário **aceitar**, o valor `granted` é salvo no `localStorage` e a coleta de dados é iniciada. | ||||||||||||||||||
| - Se o usuário **recusar**, o valor `denied` é salvo e nenhum dado é coletado. | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Controle programático | ||||||||||||||||||
|
|
||||||||||||||||||
| O `PoTelemetryService` expõe métodos para controle programático do consentimento: | ||||||||||||||||||
|
|
||||||||||||||||||
| ```typescript | ||||||||||||||||||
| import { PoTelemetryService } from '@po-ui/ng-components'; | ||||||||||||||||||
|
|
||||||||||||||||||
| @Component({ ... }) | ||||||||||||||||||
| export class SettingsComponent { | ||||||||||||||||||
| constructor(private telemetryService: PoTelemetryService) {} | ||||||||||||||||||
|
|
||||||||||||||||||
| enableTelemetry() { | ||||||||||||||||||
| this.telemetryService.grantConsent(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| disableTelemetry() { | ||||||||||||||||||
| this.telemetryService.revokeConsent(); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| ``` | ||||||||||||||||||
|
|
||||||||||||||||||
| ### Como desabilitar | ||||||||||||||||||
|
|
||||||||||||||||||
| Para desabilitar completamente a telemetria, basta: | ||||||||||||||||||
|
|
||||||||||||||||||
| - **Não importar** o `PoTelemetryModule.forRoot()` na aplicação, ou | ||||||||||||||||||
| - Definir `enabled: false` na configuração | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+112
to
+113
|
||||||||||||||||||
| - Definir `enabled: false` na configuração | |
| - Definir `enabled: false` na configuração, mantendo um `endpointUrl` válido conforme a tipagem de `PoTelemetryConfig`: | |
| ```typescript | |
| PoTelemetryModule.forRoot({ | |
| enabled: false, | |
| endpointUrl: 'https://my-telemetry-api.example.com/events' | |
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export * from './po-telemetry-config.interface'; | ||
| export * from './po-telemetry.injection-token'; | ||
| export * from './po-telemetry.module'; | ||
| export * from './po-telemetry.service'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * @usedBy PoTelemetryModule, PoTelemetryService | ||
| * | ||
| * @description | ||
| * | ||
| * Interface de configuração do serviço de telemetria. | ||
| */ | ||
| export interface PoTelemetryConfig { | ||
| /** Se a telemetria está habilitada (default: false — opt-in). */ | ||
| enabled: boolean; | ||
|
|
||
| /** URL do endpoint que receberá os eventos. */ | ||
| endpointUrl: string; | ||
|
Comment on lines
+9
to
+13
|
||
|
|
||
| /** | ||
| * Chave no `localStorage` para armazenar consentimento do usuário. | ||
| * | ||
| * @default `po-telemetry-consent` | ||
| */ | ||
| consentStorageKey?: string; | ||
|
|
||
| /** | ||
| * Intervalo em milissegundos para envio em batch. | ||
| * | ||
| * @default `30000` | ||
| */ | ||
| batchIntervalMs?: number; | ||
|
|
||
| /** | ||
| * Exibir diálogo de consentimento ao usuário na primeira vez. | ||
| * | ||
| * @default `true` | ||
| */ | ||
| showConsentDialog?: boolean; | ||
|
|
||
| /** Literais customizadas para o diálogo de consentimento. */ | ||
| consentDialogLiterals?: { | ||
| title?: string; | ||
| message?: string; | ||
| confirm?: string; | ||
| cancel?: string; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { InjectionToken } from '@angular/core'; | ||
|
|
||
| import { PoTelemetryConfig } from './po-telemetry-config.interface'; | ||
|
|
||
| export const PO_TELEMETRY_CONFIG = new InjectionToken<PoTelemetryConfig>('PO_TELEMETRY_CONFIG'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { ModuleWithProviders, NgModule } from '@angular/core'; | ||
|
|
||
| import { PO_TELEMETRY_CONFIG } from './po-telemetry.injection-token'; | ||
| import { PoTelemetryConfig } from './po-telemetry-config.interface'; | ||
| import { PoTelemetryService } from './po-telemetry.service'; | ||
|
|
||
| /** | ||
| * @description | ||
| * | ||
| * Módulo do serviço de telemetria do PO UI. | ||
| * | ||
| * Para utilização do serviço de telemetria, deve-se importar este módulo e invocar o método `forRoot`, | ||
| * informando um objeto que implementa a interface `PoTelemetryConfig`. | ||
| * | ||
| * A telemetria é **opt-in** e requer consentimento do usuário. | ||
| * | ||
| * **Exemplo de configuração:** | ||
| * | ||
| * ``` | ||
| * import { PoTelemetryModule } from '@po-ui/ng-components'; | ||
| * | ||
| * @NgModule({ | ||
| * imports: [ | ||
| * PoModule, | ||
| * PoTelemetryModule.forRoot({ | ||
| * enabled: true, | ||
| * endpointUrl: 'https://my-telemetry-api.example.com/events', | ||
| * showConsentDialog: true | ||
| * }) | ||
| * ] | ||
| * }) | ||
| * export class AppModule {} | ||
| * ``` | ||
| */ | ||
| @NgModule({}) | ||
| export class PoTelemetryModule { | ||
| static forRoot(config: PoTelemetryConfig): ModuleWithProviders<PoTelemetryModule> { | ||
| return { | ||
| ngModule: PoTelemetryModule, | ||
| providers: [{ provide: PO_TELEMETRY_CONFIG, useValue: config }, PoTelemetryService] | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As linhas de tabela estão começando com
||(ex.:|| Campo | ...), o que geralmente impede a renderização correta em Markdown. Trocar para a sintaxe padrão| Campo | ... |melhora a leitura no portal e no GitHub.