xd designers / shop-affiliate-marketing
为 SilverShop 订单添加了联盟营销 s2s postback 支持
0.1.2
2021-07-07 13:24 UTC
Requires
- silverstripe/cms: >=4.0
- silverstripe/framework: >=4.0
README
该模块将联盟营销 s2s postback 支持添加到 SilverShop 订单中。该模块包含一个抽象的 AffiliateProvider 类,可以基于不同的提供商实现。已经存在一个针对 Tune 的 HasOffers 平台默认实现。
是什么
联盟营销由市场人员用于通过联盟网络生成潜在客户。例如,联盟合作伙伴可以在博客文章中使用带有联盟 id 的链接。
配置
Has Offers
您可以在 Has Offers 实现中配置以下参数
XD\Shop\AffiliateMarketing\Providers\HasOffers: default_offer_id: 71 # the default offer to map your conversions to transaction_id_var: 'clickid' # the query parameter name that holds the transaction id affiliate_id_var: 'pub' # the query parameter name that holds the affiliate id
如果您处理多个目标或 offers id,并且不想使用默认参数,可以扩展 HasOffers
类
class HasOffersExtension extends Extension { public function onBeforePostBack(&$query, $order) { // if the order matches the case of the different offer or goal if ($order->matchesDifferentCase()) { $query['offer_id'] = 'my_offer_id'; } } }
创建自定义 AffiliateProvider
如果您有不同的联盟提供商,可以扩展抽象的 AffiliateProvider 类并实现 sessionFromRequest
和 doPostBack
方法。第一个方法用于从会话中获取和存储您需要用于 postback 的 id。当订单支付时调用 doPostBack
方法,该方法应调用存储的 id 的提供商服务器。
class MyAffiliateProvider extends AffiliateProvider { /** * Set the required session data from the request */ public function sessionFromRequest(HTTPRequest $request) { $transactionId = $request->getVar('transaction_id'); $affiliateId = $request->getVar('affiliate_id'); if ($transactionId && $affiliateId) { $session = $request->getSession(); $session->set('MyAffiliateProvider.TransactionID', $transactionId); $session->set('MyAffiliateProvider.AffiliateID', $affiliateId); $session->save($request); } } /** * Handle the postback to the affiliate provider */ public function doPostBack(HTTPRequest $request, Order $order) { // send the postback to your affiliate partners server } }
配置注入器以使用您的自定义联盟提供商
SilverStripe\Core\Injector\Injector: AffiliateProvider: class: MyAffiliateProvider