Google AnalyticsUser Guide
Google Analytics is a support library that aids Fantom-Factory Ltd in the development of other libraries, frameworks and applications. Though you are welcome to use it, you may find features are missing and the documentation incomplete.
Overview
Google Analytics is a simple service that sends page views and events to Google's Universal Analytics script.
It uses Duvet to render Javascript in HTML pages.
Quick Start
Set the Google Analytic account in your AppModule
:
using afIoc using afIocConig using afGoogleAnalytics const class AppModule { @Contribute { serviceType=ApplicationDefaults# } Void contributeApplicationDefaults(Configuration config) { config[GoogleAnalyticsConfigIds.accountNumber] = "XX-99999999-9" config[GoogleAnalyticsConfigIds.accountDomain] = `http://example.org/`// optional, defaults to 'auto'} }
Or set the properies in config.props
(See IoC Config)
afGoogleAnalytics.accountNumber = XX-99999999-9 afGoogleAnalytics.accountDomain = http://example.org/ // optional, defaults to 'auto'
The domain is optional and will be taken from the Bedsheet host / request host parameter if not supplied.
Then render the required Javascript via the GoogleAnalytics
service:
using afGoogleAnalytics::GoogleAnalytics ... @Inject GoogleAnalytics googleAnalytics ... googleAnalytics.renderPageView()
Content-Security-Policy
GoogleAnalytics automatically updates any Content-Security-Policy HTTP response headers with all neccessary directives. But if you wish to add them manually, it's been observed that the following are required:
script-src https", "https://www.google-analytics.com img-src https", "https://www.google-analytics.com connect-src https", "https://www.google-analytics.com
Debugging
Note that Javascript is only rendered in prod
mode (see IoC Env for details). Enable debugging if want to see the generated google analytics javascript in the logs:
Log.get("afGoogleAnalytics").level = LogLevel.debug