xruff / googleanalytics
Nette extension - Google Analytics code
Requires
- nette/application: ^3.0
- nette/security: ^3.0
Requires (Dev)
- nette/tester: ^2.0
- tracy/tracy: ^2.6
- vanio/coding-standards: ^0.1@dev
README
Requirements
Package requires PHP 5.6 or higher
Installation
The best way to install XRuff/GoogleAnalytics is using Composer:
$ composer require xruff/googleanalytics
Documentation
Configuration in config.neon. Both parameters are optional.
If parameter code
is missing, GA code will not be rendered in template. If parameter user
is missing, default settings will be used - value on
. If paramter user
is on
and user is logged in, google analytics code will contain directive ga('set', 'userId', {$user->id});
extensions: googleAnalytics: XRuff\App\UI\Components\DI\GoogleAnalyticsExtension googleAnalytics: code: UA-123456789-1 user: on # on/off - display user ID if user is logged in
Base presenter:
use XRuff\App\UI\Components\IGoogleAnalyticsControlFactory; abstract class BasePresenter extends Nette\Application\UI\Presenter { /** @var IGoogleAnalyticsControlFactory $googleAnalyticsControlFactory @inject */ public $googleAnalyticsControlFactory; protected function createComponentGoogleAnalytics() { return $this->googleAnalyticsControlFactory->create(); } }
@layout.latte:
... </head> <body> {control googleAnalytics} ...
You can invoke parameters into control in latte template. 1st parameter is GA code. 2nd parameter should be boolean and manage displaying GA directive for user's session - ga('set', 'userId', {$user->id});
. Both parameters are optioanl.
... </head> <body> {control googleAnalytics 'UA-123456789-2', false} ...
Repository https://github.com/XRuff/GoogleAnalytics.