yii-dream-team / yii2-tracking-controller
Yii2 tracking controller behavior
Installs: 1 696
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 5
Forks: 3
Open Issues: 0
Type:yii-extension
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-11-17 19:29:18 UTC
README
Yii2 controller behavior that captures tracking params from the query. Captured parameters are stored in session and you can access them any time.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii-dream-team/yii2-tracking-controller "*"
or add
"yii-dream-team/yii2-tracking-controller": "*"
to the require
section of your composer.json.
Usage as controller behavior
Attach the behavior to your controller class:
public function behaviors()
{
return [
'utm_campaign' => [
'class' => '\yiidreamteam\behaviors\TrackingController',
'queryParam' => 'utm_campaign',
'sessionParam' => 'utm_campaign',
],
'utm_source' => [
'class' => '\yiidreamteam\behaviors\TrackingController',
'queryParam' => 'utm_source',
'sessionParam' => 'utm_source',
],
];
}
Single param tracking:
$utmCampaign = $this->trackingParam;
Or
$utmCampaign = $this->getTrackingParam('unknown_campaign');
Tracking multiple parameters:
$utmSource = $this->behaviors['utm_source']->trackingParam;
$utmCampaign = $this->behaviors['utm_campaign']->trackingParam;
Or:
$utmSource = $this->behaviors['utm_source']->getTrackingParam('unknown_source');
$utmCampaign = $this->behaviors['utm_campaign']->getTrackingParam('unknown_campaign');
Licence
MIT