Socket
Socket
Sign inDemoInstall

angular-ga

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-ga

> Google Analytics for your Angular application


Version published
Weekly downloads
170
decreased by-7.1%
Maintainers
1
Weekly downloads
 
Created
Source

angular-ga Build Status

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.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { GoogleAnalyticsModule, GA_TOKEN } from 'angular-ga';

import { AppComponent } from './app.component';

@NgModule({
	imports: [
		BrowserModule,
		GoogleAnalyticsModule.forRoot({
			provide: GA_TOKEN,
			useValue: 'UA-TOKEN-1'
		})
	],
	declarations: [
		AppComponent
	],
	bootstrap: [AppComponent]
})
export class AppModule { }

Service

Inject the GoogleAnalyticsService into your components or services.

import { Component, OnInit } from '@angular/core';
import { GoogleAnalyticsService } from 'angular-ga';

@Component({
	moduleId: module.id,
	templateUrl: 'app.component.html'
})
export class AppComponent implements OnInit {

	constructor(
		private gaService: GoogleAnalyticsService
	) { }

	ngOnInit() {
		this.gaService.event.emit({
			category: 'app',
			action: 'bootstrap'
		});
	}
}

API

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.

License

MIT © Sam Verschueren

Keywords

FAQs

Package last updated on 01 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc