altis/experiments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

altis/experiments

Composer 安装命令:

composer require altis/experiments

包简介

Web Experimentation framework for Altis

README 文档

README

Web Experimentation framework for Altis.

Features

The plugin currently provides the following built in features:

Post Title A/B Tests

With this feature enabled it's simple to create A/B Tests for your post titles directly from the post edit screen.

It is enabled by default but can be disabled using the following filter:

add_filter( 'altis.experiments.features.titles', '__return_false' );

Posts and pages are supported by default however you can add support for custom post types using the following code in a plugin or your theme's functions.php:

add_post_type_support( 'events', 'altis.experiments.titles' );

Usage

The plugin provides a programmatic API to register custom A/B Tests for post data:

register_post_ab_test( string $test_id, array $options )

Sets up the test.

  • $test_id: A unique ID for the test.
  • $options: Configuration options for the test.
    • label <string>: A human readable label for the test.
    • rest_api_variants_field <string>: The field name to make variants available at.
    • rest_api_variants_type <string>: The data type of the variants.
    • goal <string>: The conversion goal event name, eg "click" or "click:.selector a".
    • goal_filter <string | callable>: Elasticsearch bool query to filter goal results. If a callable is passed it receives the test ID and post ID as arguments.
    • query_filter <string | callable>: Elasticsearch bool query to filter total events being queried. If a callable is passed it receives the test ID and post ID as arguments.
    • variant_callback <callable>: An optional callback used to render variants based. Arguments:
      • $value <mixed>: The variant value.
      • $post_id <int>: The post ID.
      • $args <array>: Optional args passed to output_ab_test_html_for_post().
    • winner_callback <callable>: An optional callback used to perform updates to the post when a winner is found. Defaults to no-op. Arguments:
      • $post_id <int>: The post ID
      • $value <mixed>: The winning variant value.
    • post_types <array>: An array of supported post types for the test.

output_ab_test_html_for_post( string $test_id, int $post_id, string $default_content, array $args = [] )

Returns the A/B Test markup for client side processing.

  • $test_id: A unique ID for the test.
  • $post_id: The post ID for the test.
  • $default_content: The default content for users not in the test.
  • $args: An optional array of data to pass through to variant_callback.
namespace Altis\Experiments;

// Register the test.
register_post_ab_test( 'featured_images', [
	'rest_api_variants_type' => 'integer',
	'goal' => 'click',
	'variant_callback' => function ( $attachment_id, $post_id, $args ) {
		return wp_get_attachment_image(
			$attachment_id,
			$args['size'],
			false,
			$args['attr']
		);
	}
] );

// Apply the test by filtering some standard output.
add_filter( 'post_thumbnail_html', function ( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
	return output_ab_test_html_for_post( 'featured_images', $post_id, $html, [
		'size' => $size,
		'attr' => $attr,
	] );
}, 10, 5 );

Goal Tracking

Conversion goals are how it is determined whether a variant has been successful or not. This is calculated as the number of conversions / number of impressions.

The click goal handler is provided out of the box and adds a click event handler to the nearest <a> tag.

Scoped Event Handling

For tests where more complex alternative HTML is being rendered you can define the event target with a CSS selector passed to element.querySelectorAll().

For example setting the goal to click:.my-target will track a conversion when the element in the variant HTML matching .my-target is clicked. This applies for all registered goal handlers.

Custom Goal Handlers

You can define your own goal handlers in JavaScript:

Altis.Analytics.Experiments.registerGoal( name <string>, callback <function>, closest <array> )

This function adds a goal handler where name corresponds to the value of $options['goal'] when registering an A/B Test.

The callback receives the following parameters:

  • element <HTMLElement>: Target node for the event.
  • record <function>: Receives the target element and a callback to log the conversion. The function accepts two optional arguments:
    • attributes <object>: Custom atttributes to record with the event.
    • metrics <object>: Custom metrics to record with the event.

The closest parameter allows you to ensure the element passed to your callback is of a certain type, achieved by stepping up through the DOM tree, for example to return only anchor tags you would pass [ 'a' ].

Altis.Analytics.Experiments.registerGoal( 'scrollIntoView', function ( element, record ) {
	var listener = function () {
		// Check element has come into view or not.
		if ( element.getBoundingClientRect().top > window.innerHeight ) {
			return;
		}

		// Remove event listener immediately.
		window.removeEventListener( 'scroll', listener );

		// Record event.
		record();
	};

	// Start listening to scroll events.
	window.addEventListener( 'scroll', listener );
} );

Note: This JavaScript should be enqueued in the <head> via the wp_enqueue_scripts action.

Creating your own tests

How you manage the variant data is up to you, for example you could use Fieldmanager or Advanced Custom Fields to create metaboxes to save the variant data.

Note you should use the following functions to get and update the variants:

get_ab_test_variants_for_post( string $test_id, int $post_id ) : array

update_ab_test_variants_for_post( string $test_id, int $post_id, array $variants )

Roadmap

  • Multivariate testing capability
  • Features
    • Featured image tests

Made with ❤️ by Human Made

altis/experiments 适用场景与选型建议

altis/experiments 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 35.05k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2019 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 altis/experiments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 altis/experiments 我们能提供哪些服务?
定制开发 / 二次开发

基于 altis/experiments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 16
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2019-07-29