PHP code example of nyx-solutions / yii2-nyx-referer-parser

1. Go to this page and download the library: Download nyx-solutions/yii2-nyx-referer-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nyx-solutions / yii2-nyx-referer-parser example snippets


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);