@financial-times/cmp-client

中文文档
7.10.2发布于 2026/11/05ESM + CJS近 30 天下载 2538

A client-side library to help you add a CMP (currently provided by Sourcepoint) to your application.

原始使用文档
文档目录12 节
  1. Installation
  2. Using the script tag
  3. Using the NPM package
  4. Usage on non-FT.com properties
  5. Usage on FT.com
  6. Opening the privacy manager
  7. CMP configuration options:
  8. Available Properties (constantly being updated)
  9. Responding to CMP events
  10. Debugging
  11. Development
  12. Branch previews

CMP Client

A client-side library to help you add a CMP (currently provided by Sourcepoint) to your application.

How it works

(Source on Confluence)

CMP Client Overview

Installation

Install as a <script> tag (recommended):

<script async src="https://consent-notice.ft.com/cmp.js"></script>

To enable development branch previews (recommended), set the script referrer policy as follows:

<script async src="https://consent-notice.ft.com/cmp.js" referrerpolicy="no-referrer-when-downgrade"></script>

Install the library from NPM:

npm install @financial-times/cmp-client

Using the script tag

The src attribute of the script tag points to an immediately invoked function expression (IIFE) that sets up the CMP client on the host page. When the CMP client is installed this way, no additional work needs to be done.

The primary benefit of using this integration method is that your users will automatically get new updates to the CMP client as soon as they are available, as opposed to requiring a version bump and application release. However, for this method to work successfully, the host page must be one of our registered properties. Please reach out to the Ads & Privacy team if you are not sure or you would like to register a property.

By default the source link integrates the latest version of the CMP client. If you would like to pin a different version, you can append a version query parameter to the source link as follows:

<script async src="https://consent-notice.ft.com/cmp.js?version=4.0.0"></script>

Using the NPM package

[!Note] We will be adding new properties (i.e. websites under FT group) and their configs as we start rolling out.

Please reach out to the Ads & Privacy team if you think your domain needs a new property config

Usage on non-FT.com properties

import {
  initSourcepointCmp,
  properties,
  interceptManageCookiesLinks,
  debug,
} from "@financial-times/cmp-client";

/**
 * Optionally enable debug mode to see CMP events in the console
 */
debug.logCmpEvents();

/**
 * Import your domain's CMP configuration from the `properties` module:
 * e.g. properties.MM_IGNITES_ASIA, properties.SP_THE_BANKER, etc.
 *
 * We will add more domains as we create new properties in Sourcepoint
 *
 * See below for the full list of initialisation options
 */
initSourcepointCmp({
  propertyConfig: properties["YOUR_PROPERTY_CONFIG_KEY"],
  useConsentStore: false, // Specialist Titles _must_ opt out of Single Consent Store
});
/**
 * Optionally enable "Manage Cookies" link util
 */
interceptManageCookiesLinks(properties["YOUR_PROPERTY_CONFIG_KEY"]);

Usage on FT.com

import {
  initSourcepointCmp,
  properties,
  interceptManageCookiesLinks,
  debug,
} from "@financial-times/cmp-client";

/**
 * Optionally enable debug mode to see CMP events in the console
 */
debug.logCmpEvents();

/**
 * We suggest using a feature flag to disable the existing cookie banner
 * and enable the new one
 */
if (flagsClient.get("adsDisableInternalCMP")) {
  initSourcepointCmp({
    propertyConfig: FT_DOTCOM_TEST,
  });
  interceptManageCookiesLinks();
}

Opening the privacy manager

Use openPrivacyManager to open the applicable privacy manager without navigating to the FT.com preferences page:

import { initSourcepointCmp, openPrivacyManager, properties } from "@financial-times/cmp-client";

initSourcepointCmp({ propertyConfig: properties.FT_DOTCOM_PROD });

manageCookiesButton.addEventListener("click", () => {
  openPrivacyManager();
});

When CMP client is loaded as a static script, use the function exposed on window.FTConsent:

window.FTConsent.cmp.openPrivacyManager();

The function uses the property configuration passed to initSourcepointCmp and waits for Sourcepoint to report the applicable legislation before opening the privacy manager. It does not open while Sourcepoint is waiting for user interaction and ignores further calls while the privacy manager is already opening or visible.

CMP configuration options:

Option Description
propertyConfig (SourcepointConfig) This config object is directly passed to Sourcepoint (our external CMP) and presets (imported like example usage) will be made available for different properties/titles under the FT group. This currently defaults to the FT_DOTCOM_PROD preset
userId (string) Please provide a userId if the user is a logged in user. If your app uses the FT Secure Session token, you can leave empty and set useFTSession to true instead. Defaults to undefined for anonymous users
useFTSession (boolean) Set this flag if you want the user's Id to be automatically derived from their FT Secure Session. Set to false if your app doesn't use FT Secure Session. Defaults to true
consentProxyHost (string) The fully qualified domain name for your consent proxy instance e.g https://consent.thebanker.com. Defaults to https://consent.ft.com
cookieDomain (string) The domain (and subdomains) that the FTConsent cookie will apply to e.g .thebanker.com. Defaults to .ft.com
formOfWordsId (string) The IAB custom categories that you have adapted might be tracked under a different FOW ID. At the moment, all custom categories are tracked under the sourcepointCmp form-of-words and it defaults to sourcepointCmp/VngD.XycZut.595cp9fWdp5XYP9vlFvk. Properties using the consent banner as presented should use the default value
useConsentStore (boolean) Specifies whether the user's consent record should also be backed by the Single Consent Store. Properties like Specialist titles will need to explicitly set this to false as true is the default behavior
disableFTCookies (boolean) Specifies whether the user's consent record should be saved to FT Cookies. Properties like Specialist titles that don't utilize FT cookies will need to explicitly set this to true as false is the default behavior
events (object) Used internally to define handlers for events emitted by the Vendor-supplied CMP module. See notes on "Responding to CMP events" below for details on how to define custom event handlers

Available Properties (constantly being updated)

Property Key Details
FT_DOTCOM_TEST

Use this configuration preset for testing the CMP on a property that has not yet been registered in the Sourcepoint portal.

All *.ft.com are currently registered and this config will spoof your request as coming from https://local.ft.com

FT_DOTCOM_PROD Configuration preset for all properties on FT.com domain operating in a production environment - https://*.ft.com
SP_THE_BANKER Configuration preset for properties on thebanker.com domain
SP_PWMNET Configuration preset for properties on pwmnet.com domain
SP_FDI_INTELLIGENCE Configuration preset for properties on fdiintelligence.com domain
SP_BANKING_RR Configuration preset for properties on bankingriskandregulation.com domain
SP_SUSTAINABLE_VIEWS Configuration preset for properties on sustainableviews.com domain
SP_FT_ADVISER Configuration preset for properties on ftadviser.com domain
SP_INVESTORS_CHRONICLE Configuration preset for properties on investorschronicle.co.uk domain
MM_IGNITES_ASIA Configuration preset for properties on ignitesasia.com domain
MM_IGNITES_EUROPE Configuration preset for properties on igniteseurope.com domain
SP_MANDATE_WIRE Configuration preset for properties on mandatewire.com domain
SP_FT_LOCATIONS Configuration preset for properties on ftlocations.com domain

Responding to CMP events

If you need to do additional work in response to events emitted by the CMP Vendor module – e.g. initialising vendor packages that match the purposes granted by the user – you can do so via the window._sp_.addEventListener method:

window._sp_.addEventListener("onMessageReady", (messageType) => {... });
window._sp_.addEventListener("onConsentReady", (legislation, consentUUID, consentString, consentMeta) => { ... });

[!Note] The onConsentReady event is fired

  1. As soon as the CMP has finished loading and the user's consent choices are available
  2. Subsequently, whenever the user's consent choices change

See the Sourcepoint docs for a full listing of the events you can listen for and the arguments passed to the callbacks.

Debugging

You can verify that the CMP is correctly configured using the logCmpEvents method exported from the debug module:

import { debug } from "@financial-times/cmp-client";

debug.logCmpEvents();

If everything's working then you'll see the CMP Module log its lifecycle events to the console, even if its UI isn't displayed.

This can easily happen when you've made a previous consent choice and the CMP is now picking it up from local storage. For this reason we recommend running in an incognito window during development.

[!Note] Please ensure that your app always uses the latest version of the CMP Client library.

You can check the version your live app is using by running the following in the browser console:

window.FT_CMP_CLIENT_VERSION

Development

If you have access to the source on Github you can take a look at the reference implementations in src/examples/cmp-client.

To see a demo in action in your browser, run:

npm run dev -w src/examples/cmp-client

Visit https://localhost:5173 (see setup details in src/examples/cmp-client) to interact with the banner and see how cookies are set accordingly

For resetting your consent cookies/record and other common troubleshooting issues, see the Troubleshooting Guide

Branch previews

You can also preview changes on your branch in a consuming app that uses the static loader script and is configured as described above. Append a cmp_preview query param as follows with its value set to the first seven digits of the branch's commit hash. This can easily be obtained in a Git-based VCS UI or using git rev-parse --short HEAD. And then appended as: https://ft.com?cmp_preview=<SHORT_COMMIT_SHA>

Resources

For a detailed deep-dive (internal only) of how the static deployment process works, the design is documented here. If you need to be granted access, please reach out to the Ads & Privacy team.

版本与发布记录

@financial-times/cmp-client 共发布 133 个版本,首次发布于 2023/10/24;过去 12 个月发布了 65 个版本。

版本发布日期距今
7.10.2latest2026/11/059 天前
7.10.12026/11/0410 天前
7.10.02026/10/2124 天前
7.9.22026/10/1629 天前
7.9.12026/10/1629 天前
7.9.02026/10/091 个月前

其他发布通道:pre-release → 5.2.1-beta.6。

关于 @financial-times/cmp-client 的常见问题

@financial-times/cmp-client 是什么?

A client-side library to help you add a CMP (currently provided by Sourcepoint) to your application.

如何安装 @financial-times/cmp-client?

在项目目录运行 npm install @financial-times/cmp-client,或使用 pnpm add / yarn add / bun add。

@financial-times/cmp-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/financial-times__cmp-client 是否存在。

@financial-times/cmp-client 支持 ESM 还是 CommonJS?

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

@financial-times/cmp-client 可以商用吗?

@financial-times/cmp-client 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@financial-times/cmp-client 的下载量有多少?

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

@financial-times/cmp-client 还在维护吗?

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