Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

lef:analytics

Install

Add this repo as git submodule to your packages folder and run meteor add lef:analytics.

Update your settings file (or provide these manually):

{
"public" : {
"ga" : {
"trackingId": "UA-000000-01",
"options": {
"debug": true
},
"optIn": false
}
}
}
propertyrequirednotes
trackingIdyesformat: UA-XXXXXX-XX
optionsno
optInnoSet to true if you want users to opt-in.
You currently need to build the opt-in modal yourself.*

Usage

Startup

In your client startup file:

import{gaInit}from'meteor/lef:analytics'// get trackingId and options from Meteor.settings or hardcodedconstgaSettings=Meteor.settings.public.ga||{trackingId: 'UA-XXXXXX-01'}Meteor.startup(()=>gaInit(gaSettings)

PageViews

In your top level component:

import{PageView}from'meteor/lef:analytics'constApp=()=>(<Routerhistory={history}><PageView><Switch><Routepath={'/contact'}exactcomponent={Contact}/><Routepath={'/'}exactcomponent={Home}/></Switch></PageView></Router>)

The PageView component takes care of every change in your pathname. Hash changes and paramteres are currently not counted for.

Events

In any component with interactivity:

import{gaEvent}from'meteor/lef:analytics'classChangeColorextendsReact.Component{changeColor(){constcolor=getRandomColor()this.setState({ color })gaEvent({category: 'Color',action: 'Change',label: color,// String// value: 1 // Number})}render(){return(<ButtononClick={this.changeColor}>Randomise color</Button>)}}

Opt-in

If you want start/stop the tracking programmatically, you can execute the init function again, with optin set to the appropriate value.

// starts tracking for trackingId UA-XXXXXX-01gaInit({trackingId: 'UA-XXXXXX-01',optIn: false})// stops tracking for trackingId UA-XXXXXX-01gaInit({trackingId: 'UA-XXXXXX-01',optIn: true})

About

Google Analytics Wrapper

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages