API Docs for: 0.8.0
Show:

AnalyticsManager Class

Provides functionality to render HTML snippets to report metrics back to registered analytics providers.

Constructor

AnalyticsManager

(
  • options
)

Parameters:

  • options Object
    • [site='global'] String optional
    • [timeout=25] Integer optional

      The amount of time, in milliseconds, that the manager will wait for each provider to render.

Methods

buildDomainErrorHandler

(
  • opts
)
Function static

Parameters:

  • opts Object
    • key String
    • method String
    • url String
    • start Integer

      The epoch when the provider started execution

    • th Object

      The timeout handle for the provider execution

    • callback Function

Returns:

Function:

buildProviderResponseHandler

(
  • opts
)
Function static

Parameters:

  • opts Object
    • key String
    • method String
    • url String
    • start Integer

      The epoch when the provider started execution

    • th Object

      The timeout handle for the provider execution

    • callback Function

Returns:

Function:

buildRenderTask

(
  • key
  • req
  • session
  • ls
)
Function static

Parameters:

Returns:

Function:

buildTimeoutHandler

(
  • opts
)
Function static

Parameters:

  • opts Object

Returns:

Function:

gatherData

(
  • req
  • session
  • ls
  • cb
)

Takes the provided request and session then checks with each of the registered analytics providers to ensure get the HTML snippets to be executed for analytics reporting.

Parameters:

  • req Request

    The current incoming request

  • session Object

    The current user session

  • ls Localization

    An instance of the Localization service

  • cb Function

    A callback that provides two parameters. An error, if occurred, and a TemplateValue representing the HTML snippets for the analytic providers.

getKeys

(
  • site
)
Array static

Parameters:

  • site String

Returns:

Array:

getStats

() Object static

Retrieves timing metrics for analytic providers. Handy for debugging timeouts

Returns:

Object:

getStats

() Object static

Updates the runtime statistics to include

Returns:

Object:

isRegistered

(
  • name
  • [site='global']
)
Boolean static

Indicates if an analytics provider with the specified name has already registered itself.

Parameters:

  • name String

    The name of the analytics provider to check registration for

  • [site='global'] String optional

Returns:

Boolean:

TRUE when the provider is registered, FALSE if not

keyHandler

(
  • keyHash
)
Function private static

Parameters:

  • keyHash Object

Returns:

Function:

onPageRender

(
  • req
  • session
  • ls
  • cb
)
static

Called when a page is rendering. It creates a new instance of the analytics manager and constructs the javascript snippets (wrappered in TemplateValue) needed for the analytics plugins

Parameters:

  • req Request
  • session Object
  • ls Localization
  • cb Function

    A callback that provides two parameters. An error, if occurred, and a TemplateValue representing the HTML snippets for the analytic providers.

registerProvider

(
  • name
  • [site='global']
  • onPageRendering
)
static

Registers an analytics provider. When a template is being rendered and encounters the ^analytics^ directive "onPageRender" is called.

Parameters:

  • name String

    The provider's name

  • [site='global'] String optional
  • onPageRendering Function

    A function that is called for every requests that intends to execute HTML snippets to track analytics. The function is expected to take 4 parameters. The first is the current Request object. The second is the current user session object. The third is an instance of Localization. The last is a callback that should be called with two parameters. The first is an error, if occurred and the second is raw HTML string that represents the snippet to be executed by the analytics plugin.

unregisterProvider

(
  • name
  • [site='global']
)
Boolean static

Unregisters an analytics provider

Parameters:

  • name String
  • [site='global'] String optional

Returns:

Boolean:

TRUE if was unregistered, FALSE if not found

updateStatBlock

(
  • runTime
  • block
)
private static

Parameters:

  • runTime Integer

    The amount of time that the provider ran in milliseconds

  • block Object

    The block that contains the stats for the provider

Properties

DEFAULT_RESULT

String private static

The value provided as the result of the rendering when there is nothing to perform for a task

DEFAULT_TIMEOUT

Integer private static

The default amount of time, in milliseconds that the manager will wait for each provider to render.

PROVIDER_HOOKS

Object private static

Stores the registered analytics providers

site

String

The site context for the instance

STATS

Object private static

Stores the registered runtime metrics for the providers

timeout

Integer

The amount of time, in milliseconds, that the manager will wait for each provider to render.