nox-it / yii2-nox-referer-parser
此包已被废弃,不再维护。未建议替换包。
Yii2 Referer 解析器
2.0.0
2020-05-03 15:35 UTC
Requires
- php: >=7.4.0
- nox-it/yii2-nox: ~2.0.0
- nox-it/yii2-nox-helpers: ~2.0.0
- nox-it/yii2-nox-mvc: ~2.0.0
- nox-it/yii2-nox-user-agent-parser: ~2.0.0
- snowplow/referer-parser: ~0.2.0
README
NOX 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
文件。