nyx-solutions / yii2-nyx-referer-parser
Yii2 Referer Parser
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 Parser is a PHP library for extracting marketing attribution data (such as search terms) from referer URLs.
Installation
The preferred way to install this extension is through composer.
- Either run
php composer.phar require --prefer-dist "nyx-solutions/yii2-nyx-referer-parser" "*"
or add
"nyx-solutions/yii2-nyx-referer-parser": "*"
to the require
section of your application's composer.json
file.
Usage
In components (in the following example we get the RefererParser data and pass to the PublicAccessLog
model, which in this case is just an example):
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 }
In the Controller Action:
$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);
License
yii2-nyx-referer-parser is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.