Google Analytics Connector

Reshuffle Google Analytics Connector

npm install reshuffle-google-connectors

ES6 import: import { GoogleAnalyticsConnector } from 'reshuffle-google-connectors'

This is a Reshuffle connector that provides an Interface to the Google Analytics Platform.

This connector uses Universal Analytics package.

Example

const { GoogleAnalyticsConnector } = require('reshuffle-google-connectors')
const app = new Reshuffle()

const options = { trackingId: 'UA-XXXXXXXXX-Y' }

const gaConnector = new GoogleAnalyticsConnector(app, options)

gaConnector.trackEvent('my category', 'my action') // Capture an event in Google Analytics

Table of Contents

Setup Google Analytics (get a tracking id)

Configuration Options

Connector Events

N/A

Connector Actions

Track Event

Track Page View

SDK - Get a universal analytics client

Setup Google Analytics (get a tracking id)

  1. Log in to Google Analytics Platform
  2. 'Admin' > 'Create a property'
  3. Enter a property name
  4. Click on 'Show Advanced Options'
  5. Switch on 'Create a Universal Analytics property'
  6. Select 'Create a Universal Analytics property only'
  7. In Website URL, use your Reshuffle runtime URL
  8. Click 'Next' then 'Create'
  9. Copy your tracking ID (e.g. UA-XXXXXXXXX-Y)
  10. Provide this tracking ID when creating your Reshuffle connector (see below instructions)

Configuration Options

export interface GoogleAnalyticsConnectorConfigOptions {
    trackingId: string // Google Analytics Tracking Identifier (e.g. UA-XXXXXXXXX-Y)
    clientId?: string
    uaOptions?: ua.VisitorOptions
}

Example:

const { GoogleAnalyticsConnector } = require('reshuffle-google-connectors')
const app = new Reshuffle()

const gaConnector = new GoogleAnalyticsConnector(app, { trackingId: 'UA-XXXXXXXXX-Y' })

Connector events

N/A

Track Event

For tracking custom events

trackEvent(category: string, action: string, label?: string, value?: string|number) : Promise<void>

Track Page View

For tracking page views

trackPageView(path: string, hostname?: string, title?: string): Promise<void>

SDK

Returns a Universal Analytics client (See details on npm)

 sdk() : ua.Visitor

See ua.Visitor class in Universal Analytics Visitor type

Example using the sdk:

const app = new Reshuffle()
const options = { trackingId: 'UA-XXXXXXXXX-Y' }
const gaConnector = new GoogleAnalyticsConnector(app, options)

await gaConnector.sdk().event(category, action).send()