Package requires PHP 5.6 or higher
The best way to install XRuff/GoogleAnalytics is using Composer:
$ composer require xruff/googleanalyticsConfiguration 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 inBase 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.