symbiote/silverstripe-local-personalisation
Composer 安装命令:
composer require symbiote/silverstripe-local-personalisation
包简介
Builds a profile of a site user in their browser, to be used for content personalisation
README 文档
README
Overview
Builds a profile of a visitor, "tagging" behaviour based on the pages visited, actions performed, location, or device characteristics. Preserves privacy since the profile is stored in the browser only, without relying on server data or logged-in user information.
This module enables marketers and developers to collaborate effectively, by providing both a CMS user interface and an API.
CMS users can define "rule sets" to group one or more "rules". Each rule determines when and how behaviour should be tagged. For example, "if URL contains 'marketing', then add 'interested-in-marketing' tag".
These tags can then be used for matching rules against objects managed in the CMS (such as pages or content blocks), and show/hide them based on in-browser decisions. Alternatively, you can control this behaviour programmatically, enabling sophisticated rule definitions that wouldn't be feasible in a CMS UI.
Because all decision making happens in the browser, you can still serve cached responses with all variations delivered to the browser, but only some variations shown to the visitor.
Example use cases:
- Show location-specific announcements on the homepage
- List featured products from the closest store (via browser geolocation)
- Show topic-specific content blocks based on the pages the visitor has previously viewed
- Show promotions for a specific marketing campaign, based on traffic coming in with a campaign URL parameter
- Hide welcome message if the visitor has seen it before
- Show "Contact helpdesk?" call-to-action if visitors view a FAQ entry for longer than 30 seconds
Limitations:
- All variations are visible to all visitors (for example, this can't be used for targeted promo codes)
- All decision making is visible in the browser (including any built-in bias and dodgy marketing tactics)
Installation
Composer
composer require symbiote/silverstripe-local-personalisation:~1.0
Javascript and CSS
Add the required frontend logic into your main template:
<% require javascript('symbiote/silverstripe-local-personalisation:app/dist/main.js') %>
<% require css('symbiote/silverstripe-local-personalisation:app/dist/main.css') %>
Alternatively, check app/webpack.config.js on how to compile the requirements into your own frontend bundle.
Metadata
Personalisation rules are loaded as JavaScript metadata.
<script type="application/javascript" src="/__personalisation/rules"></script>
By loading this as a separate route, you avoid inline scripts and make it easier to secure your website with a Content Security Policy. It also helps with caching: Personalisation rules apply immediately on save, even when the page output might be cached (via HTTP caching or static publishing).
Apply the extension
In order for the frontend logic to be triggered, you generally want to apply an extension to at least one content object. This adds a new "Personalisation" tab in the CMS.
Apply on pages:
SilverStripe\CMS\Model\SiteTree: extensions: - Symbiote\Personalisation\PersonalisationExtension
Apply on content blocks:
DNADesign\Elemental\Models\BaseElement: extensions: - Symbiote\Personalisation\PersonalisationExtension
Modify templates
Now add some metadata to the markup for the content object you're rendering:
$p13nClasses to your class attribute, and $p13nAttributes to the element.
Example for the content blocks holder template
(store in themes/mytheme/templates/DNADesign/Elemental/Layout/ElementHolder.ss):
<div class=" element $SimpleClassName.LowerCase <% if $StyleVariant %> $StyleVariant<% end_if %> <% if $ExtraClass %> $ExtraClass<% end_if %> $p13nClasses.RAW " id="$Anchor" $p13nAttributes.RAW > $Element </div>
Test Operation
You should be ready to define rules now. Check for Profile.js console messages in your browser
to ensure everything is set up correctly.
Developer Usage
Rules for profile segmentation
Rules are defined in the CMS
They can be triggered for;
- A regex match against content
Manually applying rules
By applying the PersonalisationExtension to a content object,
you can use $p13nClasses and $p13nAttributes in your templates.
Alternatively, you can build the required markers from scratch:
- add the
lp-item cssclass - Add the
data-lp-tagsattribute to list (comma separated) the tags applied on the profile to trigger this element - Add the
data-lp-typeattribute to indicate whether to "show" (default) or "hide" the element - Add the
data-lp-timesattribute (optional) to indicate how many times the user's profile has to have been tagged - Add the
data-lp-timeframeattribute to indicate what timeframe (ie-1 week) the tagging must have happened
<div class="this-thing lp-item" data-lp-tags="route-detail" data-lp-times="5" data-lp-type="hide">
<h1>What this is</h1>
</div>
Events
The following events are triggered and can be responded to in custom code
local_profile_match_taglocal_profile_apply_rulelocal_profile_add_tag
Bind to these as document.addEventListener('local_profile_add_tag', function (eventData) {})
Local Development
Build
The frontend assets are stored in app/.
You can use yarn to install dependencies and kick off a build:
cd app/
yarn install
yarn build
Javascript, HTTPS and hot reloading
To fully test the functionality locally, you'll need to run your webserver on HTTPS which is required for geolocation in most browsers now.
When developing the Javascript code for the module, it can be helpful
to get source maps (breakpoints!) and hot reloading. The module already
has a yarn devserver command. You'll need to extend the webpack.config.js
to work around CORS issues when including it in your page
(see webpack devserver docs).
module.exports = { // ... devServer: { disableHostCheck: true } };
Now you can use the dev server (usually on port 4200)
with the preferred hostname for your Silverstripe website:
<script src="https://your-hostname:4200/main.js" type="application/javascript"></script>
Caution: In order to use geolocation without HTTPS in Chrome, you need to allow insecure origins.
symbiote/silverstripe-local-personalisation 适用场景与选型建议
symbiote/silverstripe-local-personalisation 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「profile」 「silverstripe」 「personalisation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symbiote/silverstripe-local-personalisation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symbiote/silverstripe-local-personalisation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symbiote/silverstripe-local-personalisation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Wizzy Search integration for Magento 2
A module for Pluf to manage user profiles and user accounts
Analytics chooser extensions for site settings.
The Flarum extension that allows users to private their profiles.
PhpPlaisio: Profile
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2021-01-11