Skip to content

Commit 703f04c

Browse files
committed
Fix "gtag" function implementation.
1 parent 67556f9 commit 703f04c

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

projects/ngx-google-analytics/src/lib/tokens/ngx-gtag-token.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {inject, InjectionToken} from '@angular/core';
22
import {DataLayer} from '../types/data-layer.type';
3-
import {GtagFn} from '../types/gtag.type';
3+
import {GtagFn, GtagFnArgs} from '../types/gtag.type';
44
import {NGX_DATA_LAYER} from './ngx-data-layer-token';
55
import {GaWindow} from './ngx-google-analytics-window';
66
import {NGX_WINDOW} from './ngx-window-token';
@@ -10,8 +10,11 @@ import {NGX_WINDOW} from './ngx-window-token';
1010
*/
1111
export function getGtagFn(window: GaWindow, dataLayer: DataLayer): GtagFn | null {
1212
return (window)
13-
? window['gtag'] = window['gtag'] || function (...args) {
14-
dataLayer.push(args);
13+
? window['gtag'] = window['gtag'] || function () {
14+
// IMPORTANT: rest param syntax (...args) cannot be used here since "gtag" push implementation requires
15+
// "callee" information which is not available in normal array
16+
// eslint-disable-next-line prefer-rest-params
17+
dataLayer.push(arguments as unknown as GtagFnArgs);
1518
}
1619
: null;
1720
}

0 commit comments

Comments
 (0)