
interface IEventData {
  category?: string;
  action?: string;
  label?: string;
  value?: number;
  nonInteraction?: boolean;
  data?: object;
}

export interface IDataLayerObject {
  event: string;
  eventData?: IEventData;
}

export class GoogleTagManagerService {

  public triggerCustomEvent(obj: IDataLayerObject): void {
    this.pushToDataLayer(obj);
  }

  private pushToDataLayer(obj: IDataLayerObject): void {
    try {
      // @ts-ignore
      window.dataLayer = window.dataLayer || [];
      // @ts-ignore
      window.dataLayer.push(obj);
    } catch (error) {
      // console.log('GoogleTagManagerService: pushToDataLayer()', error.message);
    }
  }

}
