Socket
Book a DemoInstallSign in
Socket

@ngx-ext/google-analytics

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

@ngx-ext/google-analytics

Google Analytics for your Angular application

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

@ngx-ext/google-analytics Build Status

Google Analytics for your Angular application

Install

$ ng add @ngx-ext/google-analytics

Usage

Configuration

The Google Analytics tracking script is included in this module.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { GoogleAnalyticsModule, GA_TOKEN } from '@ngx-ext/google-analytics';
import { AppComponent } from './app.component';

@NgModule({
	imports: [
		BrowserModule,
		GoogleAnalyticsModule.forRoot()
	],
	declarations: [
		AppComponent
	],
	bootstrap: [AppComponent],
	providers: [
		{ provide: GA_TOKEN, useValue: 'UA-TOKEN-1' } // or use GoogleAnalyticsService.configure(ga-token)
	]
})
export class AppModule { }

Service

Inject the GoogleAnalyticsService into your components or services.

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

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

	constructor(
		private gaService: GoogleAnalyticsService
	) { }

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

Configuration

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

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

	constructor(
		private gaService: GoogleAnalyticsService
	) { }

	ngOnInit() {
		this.gaService.configure('UA-TOKEN-1');
	}
}

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)

Keywords

angular

FAQs

Package last updated on 21 Jul 2021

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.