@0bsnetwork/event-sender 中文文档教程

发布于 6年前 浏览 22 项目主页 更新于 3年前

Event Sender

用于从 0bsnetwork 客户端 JS 应用程序发送分析事件的接口。


用法:

import EventSender from '@0bsnetwork/event-sender';

// EventSender is a singleton, so any new attemps at instantiation
// will return a reference to a previously created instance
const sender = new EventSender();

// E.g.
const sender2 = new EventSender();
sender === sender2 // true


// Static method .inactive() returns an instance of EventSender that queues events,
// but does not send them until .activate() method is called
const sender = EventSender.inactive();

// (!) If an EventSender instance has been activated before, this will
// return a reference to it, so it WILL be active.



/** Queue custom event */
sender.push('Product', 'GetClientClick', 'my_custom_label', 2.0);

/**
 * Queue page view
 * Useful for SPA page transitions when no
 * pageView event is tracked by default.
 */
sender.pushPageView(window.location.href, document.referrer);


// Enables sending events, including those queued before.
sender.activate();


// EventSender methods are chainable:
sender
  .activate()
  .push('Product', 'GetClientClick', 'my_custom_label', 2.0)
  .pushPageView(window.location.href, document.referrer)
  .push('Home', 'Subscribe');

Event Sender

An interface for sending analytics events from 0bsnetwork Client JS applications.


Usage:

import EventSender from '@0bsnetwork/event-sender';

// EventSender is a singleton, so any new attemps at instantiation
// will return a reference to a previously created instance
const sender = new EventSender();

// E.g.
const sender2 = new EventSender();
sender === sender2 // true


// Static method .inactive() returns an instance of EventSender that queues events,
// but does not send them until .activate() method is called
const sender = EventSender.inactive();

// (!) If an EventSender instance has been activated before, this will
// return a reference to it, so it WILL be active.



/** Queue custom event */
sender.push('Product', 'GetClientClick', 'my_custom_label', 2.0);

/**
 * Queue page view
 * Useful for SPA page transitions when no
 * pageView event is tracked by default.
 */
sender.pushPageView(window.location.href, document.referrer);


// Enables sending events, including those queued before.
sender.activate();


// EventSender methods are chainable:
sender
  .activate()
  .push('Product', 'GetClientClick', 'my_custom_label', 2.0)
  .pushPageView(window.location.href, document.referrer)
  .push('Home', 'Subscribe');
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文