nyx-solutions / yii2-nyx-referer-parser
Yii2 Referer 解析器
5.0.1
2022-06-02 14:48 UTC
Requires
- php: >=8.1.0 <8.2
- nyx-solutions/yii2-nyx: ~5.0.0
- nyx-solutions/yii2-nyx-helpers: ~5.0.0
- nyx-solutions/yii2-nyx-mvc: ~5.0.0
- nyx-solutions/yii2-nyx-user-agent-parser: ~5.0.0
- snowplow/referer-parser: ~0.2.0
README
NYX Referer 解析器是一个PHP库,用于从引用URL中提取营销归因数据(如搜索词)。
安装
安装此扩展的首选方式是通过 composer。
- 运行以下命令:
php composer.phar require --prefer-dist "nyx-solutions/yii2-nyx-referer-parser" "*"
或者在您的应用程序的 composer.json
文件的 require
部分添加以下内容:
"nyx-solutions/yii2-nyx-referer-parser": "*"
使用方法
在组件中(以下示例中我们获取 RefererParser 数据并将其传递给 PublicAccessLog
模型,在此示例中只是一个例子)
namespace common\components\http; use common\models\PublicAccessLog; /** * Class RefererParser * * @package common\components\http */ class RefererParser extends \nyx\components\http\referer\RefererParser { #region Constants const TYPE_GOOGLE_ORGANIC = PublicAccessLog::TYPE_GOOGLE_ORGANIC; const TYPE_GOOGLE_ADS = PublicAccessLog::TYPE_GOOGLE_ADS; const TYPE_GOOGLE_CAMPAIGN = PublicAccessLog::TYPE_GOOGLE_CAMPAIGN; const TYPE_EXTERNAL_SEARCH = PublicAccessLog::TYPE_EXTERNAL_SEARCH; const TYPE_EXTERNAL_SITE = PublicAccessLog::TYPE_EXTERNAL_SITE; const TYPE_DIRECT = PublicAccessLog::TYPE_DIRECT; #endregion }
在控制器动作中
$refererParser = new RefererParser(); $this->publicAccessLog = new PublicAccessLog(['scenario' => PublicAccessLog::SCENARIO_INSERT]); $this->publicAccessLog->type = $refererParser->getType(); $this->publicAccessLog->description = $refererParser->getDescription(); $this->publicAccessLog->source = $refererParser->getSource(); $this->publicAccessLog->medium = $refererParser->getMedium(); $this->publicAccessLog->term = $refererParser->getTerm(); $this->publicAccessLog->content = $refererParser->getContent(); $this->publicAccessLog->campaign = $refererParser->getCampaign(); $this->publicAccessLog->device = $refererParser->getDevice(); $this->publicAccessLog->save(false);
许可证
yii2-nyx-referer-parser 采用 BSD 3-Clause 许可证发布。有关详细信息,请参阅附带文件 LICENSE.md
。