trialfireinctracker

Magento 2 的 Trialfire 追踪模块

安装: 601

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 1

开放问题: 1

类型:magento2-module

v1.1.4 2023-04-11 22:39 UTC

This package is auto-updated.

Last update: 2024-09-12 02:00:25 UTC


README

此模块为 Magento 2 添加了对 Trialfire 的支持。除了正常的用户行为追踪外,以下事件也被收集:

  • 查看分类
  • 查看产品
  • 加入购物车
  • 加入心愿单
  • 从购物车中移除
  • 开始结账
  • 完成订单
  • 订阅时事通讯
  • 注册账户

安装

从 Magento Marketplace 安装

https://marketplace.magento.com/trialfireinc-tracker.html

从命令行安装

  1. 需要 trialfireinc/tracker 包。版本标签列表可在 此处 获取。
php composer.phar require trialfireinc/tracker:v1.1.4
  1. 启用模块。
bin/magento module:enable Trialfire_Tracker --clear-static-content
bin/magento setup:upgrade
bin/magento setup:di:compile
bin/magento setup:static-content:deploy
bin/magento cache:clean

配置

唯一必需的配置是 Trialfire 项目中的 API 密钥。您可以通过登录 Trialfire 账户并转到 设置 > 追踪代码和 API 密钥 来找到 API 密钥。

  1. 打开您的商店管理后台页面,转到 商店 > 配置,然后点击 Trialfire 选项卡。

  2. 启用追踪 字段设置为 ,然后将您的 API 密钥输入到 API 令牌 字段中。

  3. 保存配置。

  4. 刷新 配置块 HTML全页 缓存。您可以从 系统 > 缓存管理 中清除缓存,或使用命令 bin/magento cache:flush config block_html full_page

高级配置

完整文档可在 此处 获取。

自定义初始化

自定义如何将 Trialfire 追踪代码包含到 DOM 中。默认实现类似于以下内容:

var s = document.createElement('script');
s.src = this.assetUrl;
document.head.appendChild(s);
Trialfire.init(this.apiToken);

自定义初始化器的 this 值如下。

{
  // The value of the Asset URL setting in your store's Trialfire configuration.
  assetUrl: '...',

  // The value of the API Token setting in your store's Trialfire configuration.
  apiToken: '...',                  

  /**
   * Call the default initialization logic.
   */
  callDefaultInit: function () ...  

  /**
   * Inject the Trialfire script into the DOM but do not call Trialfire.init().
   */
  injectScript: function () ...
}

要防止 Trialfire 在 'agent' 子域名上加载,请在 初始化代码 文本区域中输入以下 JavaScript。

// If host does not start with 'agent'.
if (!location.host.startsWith('agent.myshop.com')) {
  // Invoke the default initialization logic.
  this.callDefaulInit();
}

自定义事件处理器

自定义 Trialfire 触发跟踪事件的方式。自定义事件处理器的 this 值如下。

this.event: 包含有关事件信息的对象。内容根据事件类型而异,但类似于以下内容。

this.event = {
  $name: 'placeOrder',
  apiToken: '...',
  userId: 1,
  traits: {
    email: '...',
    firstName: '...'
  },
  props: {
    orderId: '...',
    products: [{
      id: '...',
      name: '...',
      sku: '...'
    },{
      ...
    }]
  }
}

this.tfMage: 跟踪事件的服务。它包含您可能在自定义处理器中使用的实用方法。

this.tfMage = {
  /**
   * Calls the default handler for an event.
   */
  callDefaultEventHandler: function (event) ...
};

示例

要防止 Trialfire 在 'agent' 子域名上跟踪订单,请在 下单 文本区域中输入以下 JavaScript。

// If host does not start with 'agent'.
if (!location.host.startsWith('agent.myshop.com')) {
  // Invoke the default handler for this event.
  this.tfMage.callDefaultEventHandler(this.event);
}