Google Analytics as a Page Object
The complexity of the underlying HTML templates is largely a matter of style. For someone who prefers only the document information and a series of component identifiers, there is a GoogleAnalytics object in the Istarel Workshop Application Framework.
Listing: page/html/public.html
<!DOCTYPE html> <html lang="en"> {*head*} {*body*} {*google*}
This approach requires two things: a constant defining the Google account number and a method that return a GoogleAnalytics object.
Partial Listing: rsrc/ApplicationDelegate.php
class ApplicationDelegate { const GOOGLE_ACCOUNT_NUMBER = 'UA-7285492-1'; ... }
The constant can instead be defined as a global constant called GOOGLE_ACCOUNT_NUMBER. (I personally prefer class-based constants.) Each Page object has the ability to replace component identifiers with objects or text, using a method name constructed from the name of the component identifier.
Partial Listing: rsrc/page/PublicPage.php
class PublicPage extends HTML5Page { ... function expectedComponents() { return array('head', 'body', 'google'); } function replaceGoogle() { return GoogleAnalytics::googleCode(); } }