diff --git a/readme.md b/readme.md index 4b4dbc1..0faea3d 100644 --- a/readme.md +++ b/readme.md @@ -108,7 +108,7 @@ export class AppComponent implements OnInit { ## API -### service.configure(trackingId, [options]) +### service.configure(trackingId, [options], [sendPageview]) #### trackingId @@ -123,6 +123,13 @@ Default: `auto` Any of the [`Create Only Fields`](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#create). +#### sendPageview + +Type: `Boolean`
+Default: `true` + +Set this to false to prevent automatically sending a pageview when configuring the service. + ### service.event.emit(event: Event) Emit a Google Analytics event. diff --git a/src/lib/ga.service.ts b/src/lib/ga.service.ts index 3279cd1..64274ee 100644 --- a/src/lib/ga.service.ts +++ b/src/lib/ga.service.ts @@ -22,9 +22,12 @@ export class GoogleAnalyticsService { } } - configure(trackingId: string, options: TrackingOptions | string = 'auto'): void { + configure(trackingId: string, options: TrackingOptions | string = 'auto', sendPageview = true): void { this.ga('create', trackingId, options); - this.ga('send', 'pageview'); + + if (sendPageview){ + this.ga('send', 'pageview'); + } this.event.subscribe((x: Event) => { this.onEvent(x);