Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class AppComponent implements OnInit {

## API

### service.configure(trackingId, [options])
### service.configure(trackingId, [options], [sendPageview])

#### trackingId

Expand All @@ -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`<br>
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.
Expand Down
7 changes: 5 additions & 2 deletions src/lib/ga.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down