HTTPS SSH

Google Analytics v0.1.6


Written in: Fantom pod: v0.1.6 Licence: ISC

Overview

Google Analytics is a support library that aids Alien-Factory 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.

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.

Install

Install Google Analytics with the Fantom Pod Manager ( FPM ):

C:\> fpm install afGoogleAnalytics

Or install Google Analytics with fanr:

C:\> fanr install -r http://eggbox.fantomfactory.org/fanr/ afGoogleAnalytics

To use in a Fantom project, add a dependency to build.fan:

depends = ["sys 1.0", ..., "afGoogleAnalytics 0.1"]

Documentation

Full API & fandocs are available on the Eggbox - the Fantom Pod Repository.

Quick Start

Set the Google Analytic account in your AppModule:

using afIoc
using afIocConig
using afGoogleAnalytics

const class AppModule {
  @Contribute { serviceType=ApplicationDefaults# }
  static 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:

@Inject GoogleAnalytics googleAnalytics

...

googleAnalytics.sendPageView()

Note that Javascript is only rendered in prod mode. See IoC Env for details.