nox-it/yii2-nox-referer-parser

Yii2 Referer Parser


Keywords
framework, php, extension, migration, yii2
License
BSD-3-Clause

Documentation

Yii PHP Framework Version 2 / NOX Referer Parser

NOX Referer Parser is a PHP library for extracting marketing attribution data (such as search terms) from referer URLs.

Latest Stable Version Total Downloads Latest Unstable Version License Monthly Downloads Daily Downloads composer.lock

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require --prefer-dist "nox-it/yii2-nox-referer-parser" "*"

or add

"nox-it/yii2-nox-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 \nox\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-nox-referer-parser is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

Yii2