Google Analytics for your Angular application
Install
$ npm install --save angular-ga
Usage
Configuration
The Google Analytics tracking script is not included in this module. Make sure to add it to your page.
;;; ; @
It's also possible to leave the configuration empty and configure the library later on through the service.
@
Service
Inject the GoogleAnalyticsService
into your components or services.
;; @ implements OnInit { } { thisgaServiceevent; }
Configuration
;; @ implements OnInit { } { thisgaService; }
Service
API
service.configure(trackingId, [options])
trackingId
Type: string
Tracking Id.
options
Type: Object
string
Default: auto
Any of the Create Only Fields
.
service.event.emit(event: Event)
Emit a Google Analytics event.
event
category
Type: string
Typically the object that was interacted with (e.g. Video
)
action
Type: string
The type of interaction (e.g. play
)
label
Optional
Type: string
Useful for categorizing events (e.g. Fall Campaign
)
value
Optional
Type: number
A numeric value associated with the event (e.g. 42
)
service.pageview.emit(pageview: PageView)
Emit a Google Analytics page view.
pageview
page
Type: string
The path portion of a URL. This value should start with a slash (/) character.
title
Optional
Type: string
The title of the page (e.g. homepage)
License
MIT © Sam Verschueren