@atlaskit/insm

中文文档
3.0.98发布于 2026/11/07Apache-2.0TypeScriptESM + CJS近 30 天下载 3万

INSM tooling measures user-perceived interactivity of a page

原始使用文档
文档目录13 节
  1. What insm measures
  2. Common insm measurement tasks
  3. Instrumenting "heavy tasks"
  4. Adding additional information to the session
  5. Getting current insm session details
  6. Flagging when a feature is being used
  7. How to instrument insm measurement
  8. Prerequisites
  9. Installation
  10. Initialisation
  11. Starting the page session
  12. Stop interactivity tracking for the page session
  13. Tracking gate access

insm — Interactivity Session Measurement

A lightweight, session-based way to measure how interactive your experience feels to users. insm summarizes interactivity quality for the time a user spends on a page or specific view, and emits a single analytics event when the session ends.

What insm measures

  • Interactivity quality during periods of user activity within a session
  • Both active time (when users are interacting) and overall session time
  • Excludes explicitly-marked heavy/expected work so it doesn’t skew results
  • A single, session-completion event with summary statistics and optional custom properties

Common insm measurement tasks

Instrumenting "heavy tasks"

Heavy tasks which are known to cause interactivity regressions can be explicitly opted out of the interactivity measurement via explicitly marking the period of heavy work.

Use with care—prefer reducing the cost of heavy tasks over opting out of measurement. As a general rule, only initialization and non-core actions should be marked heavy.

Examples of "heavy task" periods are

  • page initialisation
    • when first loading a page — significant work will often be triggered to collect, arrange and present the page content to the user
  • paste handling
    • for the edit-page paste handler — paste handling is currently known to be computationally expensive (and for large clipboard items, can lock up the UI for seconds). Given this is a non core experience — excluding this from interactivity monitoring ensures we have signal on the core experience.
insm.session.startHeavyTask('paste-handler');
// ... perform paste work ...
insm.session.endHeavyTask('paste-handler');

Note: For tracking page initialisation - if you use the special PageLoad key, the duration will be tracked on the resulting session event.

Adding additional information to the session

Additional session information can be added through either the setProperty or the addProperties api.

setProperty

insm.session.setProperty(key: string, value: string | number | boolean): void

This api is an alternative to addProperties for scenarios such as where you have a hot path that will repeatedly fire throughout a session.

The last value for a given key will be used, and if there is a matching key from addProperties, the addProperties value will be used.

addProperties

type ValidProperty = string | number | boolean;
insm.session.addProperties(
  propsOrFactory: Record<string, ValidProperty> | (() => Record<string, ValidProperty>)
): void

This api takes either a static single-level key-value object, or callbacks which return the same and will be evaluated on session end.

When ending a session, all properties received via this api are merged, in order, into the resulting insm event’s properties; last write wins.

Callback values are evaluated at session end.

For example, for the following

insm.session.addProperties({ one: 1, two: 2 });
insm.session.addProperties(() => ({ one: 'one' }));
insm.session.addProperties({ three: 3 });

The resulting added properties will be

{ one: 'one', two: 2, three: 3 }

Getting current insm session details

insm.session.details;

This can be used to gate changes based on an individual experience.

ie.

if (insm.session.details.experienceKey === 'cc.edit-page' && gateCheck()) {
    insm.session.addProperties(() => ({
        /*potentially large or computationally large property bag */
    }));
}

Flagging when a feature is being used

insm.session.startFeature(featureName: string): void
insm.session.endFeature(featureName: string): void
useEffect(() => {
    insm.session.startFeature('comment notification');
    return () => {
        insm.session.endFeature('comment notification');
    };
}, []);

In the resulting insm event;

  • Long Animation frames will have any active features identified on them
  • The slowest active sessions will have any features used during the active session identified on them

How to instrument insm measurement

Prerequisites

Your product must have the insm library installed — insm has the same prerequisites as UFO tooling https://developer.atlassian.com/platform/ufo/react-ufo/react-ufo/getting-started/#prerequisites.

Installation

yarn add @atlaskit/insm

Initialisation

To begin instrumentation, initialise insm via invoking the init function and passing a config object as defined by your instrumentation requirements.

import { init } from '@atlaskit/insm';

export function initialiseINSM(config) {
    /* logic to get/initialise your app's analytics client */
    init(config);
}

As early as possible in the application mount timeline (ideally, before the application is mounted), initialise the insm client via the initialiseINSM function.

Important: insm will only track interactivity for explicitly allow-listed experiences — these must be configured in the config passed.

{
    getAnalyticsWebClient,
    experiences: {
        ['experience key']: {enabled: true}
    }
}

If an experience key is missing or not enabled, no session event will be emitted.

Starting the page session

On route change/start call the insm start api.

insm.start(experienceKey, {
    contentId,
    initial,
});

Note: calling this will end any existing experience (unless the experience key and properties match - in which case no session change will occur).

Updating a page session experienceKey after it's started

In some scenarios you may need to update the running sessions experience key after it has started, in these cases you can use overrideExperienceKey.

If there is a running experience, it will update the running experiences name.

If there is no running experience (ie. if the original experienceKey had not been whitelisted), it will start a new experience using the last started experienceProperties.

insm.overrideExperienceKey('new-key');

Naming guidance

Choose an experienceKey that reflects the product and content type you want to analyze.

Examples: cc.view-page, cc.edit-page, cc.live-doc

Stop interactivity tracking for the page session

Ending a page session interactivity tracking is done by either;

  • starting a new session.
  • or when a tab session ends (ie. closing tab, refreshing page)

In some scenarios (ie. when a page error boundary is hit), you will want to exit early. This is achieved by calling the following.

insm.stopEarly(reasonKey: string, description: string);

Sessions closed early are identifiable by their end details "endDetails": { stoppedBy: "early-stop", reasonKey, description }.

Note: The session is ended as soon as stopEarly is called, any addProperties handlers will called at this point.

Tracking gate access

Call gateAccess whenever a gate is evaluated or changes during the session.

insm.gateAccess('gate key', 'gate rule');

This should be wired up to any gate access libraries/tools used by your product.

版本与发布记录

@atlaskit/insm 共发布 258 个版本,首次发布于 2025/08/13;过去 12 个月发布了 250 个版本。

版本发布日期距今
3.0.98latest2026/11/07今天
3.0.972026/11/061 天前
3.0.962026/11/061 天前
3.0.952026/11/061 天前
3.0.942026/11/062 天前
3.0.932026/11/053 天前

关于 @atlaskit/insm 的常见问题

@atlaskit/insm 是什么?

INSM tooling measures user-perceived interactivity of a page

如何安装 @atlaskit/insm?

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

@atlaskit/insm 支持 TypeScript 吗?

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

@atlaskit/insm 支持 ESM 还是 CommonJS?

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

@atlaskit/insm 可以商用吗?

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

@atlaskit/insm 的下载量有多少?

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

@atlaskit/insm 还在维护吗?

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