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)
Connector Events
N/A
Connector Actions
SDK - Get a universal analytics client
Setup Google Analytics (get a tracking id)
- Log in to Google Analytics Platform
- 'Admin' > 'Create a property'
- Enter a property name
- Click on 'Show Advanced Options'
- Switch on 'Create a Universal Analytics property'
- Select 'Create a Universal Analytics property only'
- In Website URL, use your Reshuffle runtime URL
- Click 'Next' then 'Create'
- Copy your tracking ID (e.g. UA-XXXXXXXXX-Y)
- 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()