@adv-re/vendor-by-consents-loader

中文文档
1.4.0发布于 2025/09/02ISCCommonJS近 30 天下载 5161

Load vendors according to the allowed user's consents

原始使用文档
文档目录6 节
  1. Loading list of vendors
  2. Loading a single vendor
  3. Loading specific vendors
  4. Comscore
  5. Using it in Monolithic apps
  6. List of Purposes

Vendor by Consents Loader

Set of utilities to load vendors scripts according to user consents.

You only need to define purposes and specialFeatureOptins as they're the only configurable consents on the tfc.

🔴 IMPORTANT: Before following the README, be sure you're loading the Stub from Boros TCF as it's required.

Loading list of vendors

import {
  initVendorConsentsLoader,
  addVendorLoadedEventListener
} from '@adv-re/vendor-by-consents-loader'

const OPTIMIZELY_KEY = 'optimizely'

initVendorConsentsLoader({
  vendors: {
    tealium: {
      script: 'https://frtassets.fotocasa.es/external-scripts/utag-pro.js',
      consents: {
        purposes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        specialFeatureOptins: [1]
      }
    },
    [OPTIMIZELY_KEY]: {
      script: 'https://frtassets.fotocasa.es/external-scripts/optimizely.js',
      consents: {
        purposes: [1, 2]
      }
    }
  }
})

addVendorLoadedEventListener(({vendor}) => {
  vendor === OPTIMIZELY_KEY && console.log('Optimizely has been loaded')
})

Loading a single vendor

In some cases you might want to load a single vendor later in your code:

import {
  loadSingleVendorByConsent,
  addVendorLoadedEventListener
} from '@adv-re/vendor-by-consents-loader'

const GOOGLE_ADSENSE_KEY = 'google_adsense'

loadSingleVendorByConsent({
  name: GOOGLE_ADSENSE_KEY,
  script: 'https://google.com/ads.js',
  consents: {
    purposes: [5, 6]
  }
})

addVendorLoadedEventListener(({vendor}) => {
  vendor === GOOGLE_ADSENSE_KEY && console.log('Google has been loaded')
})

You can also set a vendor configuration without an specific script in case the vendor doesn't require it to work:

import {
  loadSingleVendorByConsent,
  addVendorLoadedEventListener
} from '@adv-re/vendor-by-consents-loader'

const RTB_HOUSE_KEY = 'rtb_house'

loadSingleVendorByConsent({
  name: RTB_HOUSE_KEY,
  consents: {
    purposes: [2, 6]
  }
})

addVendorLoadedEventListener(({vendor}) => {
  vendor === RTB_HOUSE_KEY && console.log('RTB House is ready')
})

Loading specific vendors

Some vendors are used across all Adevinta Spain products and, for sake of convenience, they've their own script to load them.

Comscore

import {
  addVendorLoadedEventListener,
  loadComscore
} from '@adv-re/vendor-by-consents-loader'

loadComscore({comscoreClientId: '7109919'})

addVendorLoadedEventListener(({vendor}) => {
  vendor === 'comscore' && console.log('Comscore has been loaded')
})

Using it in Monolithic apps

// First load the UMD module.
<script src="https://unpkg.com/@adv-re/vendor-by-consents-loader/umd/index.js"></script>
<script>
  // load comscore
  window.sui.vendors.loadComscore({comscoreClientId: '7109919'})
  // init vendors loader by consents
  window.sui.vendors.initVendorConsentsLoader({
    vendors: {
      tealium: {
        script: 'https://frtassets.fotocasa.es/external-scripts/utag-pro.js',
        consents: {
          purposes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
          specialFeatureOptins: [1]
        }
      }
    }
  })
  // load a single vendor by consents
  window.sui.vendors.loadSingleVendorByConsent({
    name: 'google_adsense',
    script: 'https://google.com/ads.js',
    consents: {
      purposes: [5, 6]
    }
  })
  // add evento for listening comscore load
  window.sui.vendors.addVendorLoadedEventListener(({vendor}) => {
    vendor === 'comscore' && console.log('Comscore has been loaded')
    vendor === 'tealium' && window._utag.init()
    vendor === 'google_adsense' && window.gads.startAds()
  })
  //
</script>

List of Purposes

Purposes:

  • 1 - Store and/or access information on a device
  • 2 - Select basic ads
  • 3 - Create a personalised ads profile
  • 4 - Select personalised ads
  • 5 - Create a personalised content profile
  • 6 - Select personalised content
  • 7 - Measure ad performance
  • 8 - Measure content performance
  • 9 - Apply market research to generate audience insights
  • 10 - Develop and improve products

Special Purposes

  • SP1 - Ensure security, prevent fraud, and debug
  • SP2 - Technically deliver ads or content

Features

  • F1 - Match and combine offline data sources
  • F2 - Link different devices
  • F3 - Receive and use automatically-sent device characteristics for identification

Special Features

  • SF1 - Use precise geolocation data
  • SF2 - Actively scan device characteristics for identification

版本与发布记录

@adv-re/vendor-by-consents-loader 共发布 2 个版本,首次发布于 2025/02/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.4.0latest2025/09/021.2 年前
1.3.02025/02/191.7 年前

关于 @adv-re/vendor-by-consents-loader 的常见问题

@adv-re/vendor-by-consents-loader 是什么?

Load vendors according to the allowed user's consents

如何安装 @adv-re/vendor-by-consents-loader?

在项目目录运行 npm install @adv-re/vendor-by-consents-loader,或使用 pnpm add / yarn add / bun add。

@adv-re/vendor-by-consents-loader 支持 TypeScript 吗?

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

@adv-re/vendor-by-consents-loader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adv-re/vendor-by-consents-loader 可以商用吗?

@adv-re/vendor-by-consents-loader 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adv-re/vendor-by-consents-loader 的下载量有多少?

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

@adv-re/vendor-by-consents-loader 还在维护吗?

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