You might tell yourself “why do I need this, including a bunch of Google Analytics code is not that hard” - and you would be right - but the more services you rely on the harder it gets to manage them (like - exponentially harder), so why not make your life easier from the beginning.
So, lets try a concrete example - we want to add Google Analytics. Our config code would look something like this:
1 2 3 4 5 6 7 8 9 10 11
And you will need to have a
<?php echo Service::all_bodies(); ?> in the end of your main HTML template body, and
<?php echo Service::all_heads(); ?> in the head tag of the template, allowing any service to position its asset files in the most convenient location. But that’s about it - you now have a service that works only in Production environment, and even then it will be disabled for logged in users that have the role “admin” - pretty neat, ah?
There is a lot of built in services already available, for example, enabling chartbeat is just a few lines of config:
'chartbeat' => array( 'enabled' => Kohana::$environment === array(Kohana::PRODUCTION, 'config' => array('uid' => 'your key' , 'domain' => 'your domain'), ),
But the main idea is that any service is easily converted to this system and you can create your own services for internal APIs and whatnot with the same flexibility of deployment. You just have to override the relevant abstract methods and you’re good to go.