@atlaskit/teams-app-internal-analytics

中文文档
2.5.0发布于 2026/10/28Apache-2.0TypeScriptESM + CJS近 30 天下载 3万

A package used by the teams app and platform packages to handle people and teams analytics

原始使用文档
文档目录10 节
  1. Table of Contents
  2. Overview
  3. Architecture
  4. Adding New Events
  5. Event Naming Convention
  6. Analytics Context
  7. Nested Contexts
  8. Context Priority
  9. Testing Analytics
  10. Basic Test Setup

Teams App Internal Analytics

A comprehensive analytics package for the Teams app and People & Teams platform packages. This package provides type-safe analytics event definitions, context providers, and testing utilities for tracking user interactions and system behaviors.

Table of Contents

Overview

This package implements a structured analytics system that is:

  • Type-safe: All events and attributes are strongly typed
  • Declarative: Events are defined in YAML specification files
  • Hierarchical: Supports nested analytics contexts for rich metadata
  • Testable: Comprehensive testing utilities included
  • Channel-specific: Events are fired to the dedicated peopleTeams analytics channel

Architecture

analytics.spec.yaml          ← Event definitions (YAML)
        ↓
   Code Generation           ← Generates TypeScript types & hooks
        ↓
Generated Files:
├── analytics.types.ts       ← Type definitions for events
├── create-event-payload.ts  ← Event payload creation logic
└── use-analytics-events.ts  ← React hook for firing events
        ↓
    Consumers		     	 ← Use hook to fire analytics events
        ↓
Analytics Listeners          ← Events sent to 'peopleTeams' channel

Adding New Events

  1. Define the event in analytics.spec.yaml:

Event definition file specification

- button clicked (addUserToTeam):
    type: ui
    description: description of when this event fires
    attributes:
      <<: *PackageMetaDataContext
      newAttribute:
        type: string
        description: description of the new attribute
  1. Regenerate types:
yarn analytics:codegen
  1. Use the new event:
import React from 'react';
import { useAnalyticsEvents } from '@atlaskit/teams-app-internal-analytics';

function TeamMemberButton() {
    const { fireEvent } = useAnalyticsEvents();

    const handleClick = () => {
        fireEvent('ui.button.clicked.addUserToTeam', {
            testAttribute: 'memberInvite',
        });
    };

    return <button onClick={handleClick}>Invite Member</button>;
}

Event Naming Convention

Events follow this naming pattern:

  • UI Events: ui.[actionSubject].[action].[actionSubjectId]
  • Track Events: track.[actionSubject].[action].[actionSubjectId]
  • Operational Events: operational.[actionSubject].[action].[actionSubjectId]
  • Screen Events: screen.[screenName].viewed

Analytics Context

The PeopleTeamsAnalyticsContext provides hierarchical metadata that is automatically included in all events fired by child components.

Nested Contexts

<PeopleTeamsAnalyticsContext
    data={{
        source: 'teamsApp',
        attributes: { consumer: 'web' },
    }}
>
    <PeopleTeamsAnalyticsContext
        data={{
            source: 'teamsProfilePage',
            attributes: { teamId: 'team-123' },
        }}
    >
        <TeamProfile />
    </PeopleTeamsAnalyticsContext>
</PeopleTeamsAnalyticsContext>

Resulting event payload:

{
    "eventType": "ui",
    "actionSubject": "button",
    "action": "clicked",
    "actionSubjectId": "analyticsExample",
    "source": "teamsProfilePage",
    "attributes": {
        "packageName": "@atlassian/team-profile",
        "packageVersion": "X.X.X",
        "consumer": "web",
        "teamId": "team-123",
        "testAttribute": "yourValue",
        "sourceHierarchy": "teamsApp.teamsProfilePage"
    }
}

Context Priority

When contexts are nested, there is a priority system to ensure the correct metadata is appended to events sent to GASv3. Duplicate data is resolved in the following order:

  1. Event data (highest priority)
  2. Inner context data
  3. Outer context data

Note: Context attributes are only appended to events when they come from the peopleTeamsCtx namespace, such as the TeamsAppAnalyticsContext from this package. Other event payload properties like source will append to all events regardless of the context namespace.

Testing Analytics

This package includes testing utilities that help you verify analytics events are sent correctly to GASv3. These utilities use the processing logic from PeopleTeamsAnalyticsListener, ensuring that event payloads (including all provided contexts) match the expected outcome.

Basic Test Setup

import {
    createMockAnalyticsClient,
    renderWithAnalyticsListener,
} from '@atlaskit/teams-app-internal-analytics/test-utils';

const mockClient = createMockAnalyticsClient();

test('should fire analytics event on button click', async () => {
    const { user, mockClient, expectEventToBeFired } = renderWithAnalyticsListener(
        <PeopleTeamsAnalyticsContext data={{ source: 'teamsApp' }}>
            <ButtonWithAnalytics testId="analytics-button" />
        </PeopleTeamsAnalyticsContext>,
        { mockClient },
    );

    // Trigger the event
    await user.click(screen.getByTestId('analytics-button'));

    // Verify the event was fired correctly
    expectEventToBeFired('ui', {
        actionSubject: 'button',
        action: 'clicked',
        actionSubjectId: 'analyticsExample',
        source: 'teamsApp',
        attributes: expect.objectContaining({
            testAttribute: 'expectedValue',
        }),
    });
});

版本与发布记录

@atlaskit/teams-app-internal-analytics 共发布 65 个版本,首次发布于 2025/09/08;过去 12 个月发布了 42 个版本。

版本发布日期距今
2.5.0latest2026/10/2810 天前
2.4.42026/10/2315 天前
2.4.32026/10/071 个月前
2.4.22026/10/011 个月前
2.4.12026/08/262 个月前
2.4.02026/08/192 个月前

关于 @atlaskit/teams-app-internal-analytics 的常见问题

@atlaskit/teams-app-internal-analytics 是什么?

A package used by the teams app and platform packages to handle people and teams analytics

如何安装 @atlaskit/teams-app-internal-analytics?

在项目目录运行 npm install @atlaskit/teams-app-internal-analytics,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.2.0 || ^19.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@atlaskit/teams-app-internal-analytics 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@atlaskit/teams-app-internal-analytics 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@atlaskit/teams-app-internal-analytics 可以商用吗?

@atlaskit/teams-app-internal-analytics 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@atlaskit/teams-app-internal-analytics 的下载量有多少?

根据 npm 官方下载统计,@atlaskit/teams-app-internal-analytics 在 2026/10/07 – 2026/11/05 这 30 天内被下载 30,472 次,日均约 1,016 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@atlaskit/teams-app-internal-analytics 还在维护吗?

最新版本 2.5.0 发布于 2026/10/28(10 天前);至今共发布 65 个版本,其中过去 12 个月发布了 42 个;首次发布于 2025/09/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。