File tree Expand file tree Collapse file tree
projects/ngx-google-analytics/src/lib/tokens Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { inject , InjectionToken } from '@angular/core' ;
22import { DataLayer } from '../types/data-layer.type' ;
3- import { GtagFn } from '../types/gtag.type' ;
3+ import { GtagFn , GtagFnArgs } from '../types/gtag.type' ;
44import { NGX_DATA_LAYER } from './ngx-data-layer-token' ;
55import { GaWindow } from './ngx-google-analytics-window' ;
66import { NGX_WINDOW } from './ngx-window-token' ;
@@ -10,8 +10,11 @@ import {NGX_WINDOW} from './ngx-window-token';
1010 */
1111export 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}
You can’t perform that action at this time.
0 commit comments