File

src/app/services/logger/event-logger.service.ts

Index

Properties

Constructor

constructor(fba: FirebaseAnalytics, platform: Platform, userService: UserService, deviceInfo: PlatformService, afs: AngularFirestore)
Parameters :
Name Type Optional
fba FirebaseAnalytics No
platform Platform No
userService UserService No
deviceInfo PlatformService No
afs AngularFirestore No

Properties

bookRequestEvent
Default value : () => {...}

Logging placing book request event

device
Type : string
Public fba
Type : FirebaseAnalytics
Private logEvent
Default value : () => {...}

Logging event occurred in the application These logs can be find in the firebase analytics dashboard. You have the ability to query from the type of the log and values including metadata

Parameters :
Name Description
type

: Type of the logging event

metadata

: Additional data provided for the event

loginAttempt
Default value : () => {...}

Increment user login attempts

passwordForgetEvent
Default value : () => {...}

Logging account forget password change attempt

registerAttempt
Default value : () => {...}

Increment user Registration attempts

reservationAttempt
Default value : () => {...}

Increment user reservation attempts

searchAttempt
Default value : () => {...}

Logging the book searching event Incrementing the attempts also

Parameters :
Name Description
value

The value that user entered for searching

transferAcceptAttempt
Default value : () => {...}

Increment user Transfer attempts

transferRequestAttempt
Default value : () => {...}

Increment user Transfer attempts

uid
Type : string
import { Platform } from '@ionic/angular';
import { Injectable } from '@angular/core';
import { FirebaseAnalytics } from '@ionic-native/firebase-analytics/ngx';
import swal from 'sweetalert';
import { UserService } from '../user/user.service';
import { PlatformService } from '../platform/platform.service';
import { AngularFirestore } from '@angular/fire/firestore';
import * as firebase from 'firebase/app';
import { environment } from 'src/environments/environment';
firebase.initializeApp(environment.firebase);

const analytics = firebase.analytics();
@Injectable({
  providedIn: 'root'
})
export class EventLoggerService {
  device: string;
  uid: string;
  constructor(
    public fba: FirebaseAnalytics,
    private platform: Platform,
    private userService: UserService,
    private deviceInfo: PlatformService,
    private afs: AngularFirestore
  ) {
    this.device = this.platform.is('cordova') ? 'cordova' : 'non-android';
  }

  /**
   * Logging event occurred in the application
   * These logs can be find in the firebase analytics dashboard.
   * You have the ability to query from the type of the log and values including metadata
   * @param type : Type of the logging event
   * @param metadata : Additional data provided for the event
   */
  private logEvent = (type: string, metadata: Object = {}) => {
    console.log('Logging button click event');
    if (this.device === 'cordova') {
      this.fba
        .logEvent(type, metadata)
        .then((res: any) => {
          console.log(res);
        })
        .catch((error: any) => {
          swal('error', error);
          console.error(error);
        });
    }
  };

  /**
   * Logging account forget password change attempt
   */
  passwordForgetEvent = () => {
    this.logEvent('libri_forget_password', { time: new Date() });
  };

  /**
   * Logging placing book request event
   *
   */
  bookRequestEvent = value => {
    this.logEvent('book_request', { value });
  };

  /**
   * Increment user login attempts
   */
  loginAttempt = () => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('login')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) })
      .then(() => {
        const { uid } = this.userService.getCurrentUser();
        const deviceInfo = this.deviceInfo.getDeviceInfo();
        analytics.logEvent('login', {
          uid,
          ...deviceInfo
        });
      });
  };

  /**
   * Increment user Registration attempts
   */
  registerAttempt = () => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('register')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) });
  };

  /**
   * Increment user Transfer attempts
   */
  transferRequestAttempt = (title, cardnumber) => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('transfer_request')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) })
      .then(() => analytics.logEvent('transfer_request', { title, cardnumber }));
  };

  /**
   * Increment user Transfer attempts
   */
  transferAcceptAttempt = cardnumber => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('transfer_accept')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) })
      .then(() => analytics.logEvent('transfer_accept', { cardnumber }));
  };

  /**
   * Logging the book searching event
   * Incrementing the attempts also
   * @param value The value that user entered for searching
   */
  searchAttempt = value => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('search')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) })
      .then(() => analytics.logEvent('search', { value }));
  };

  /**
   * Increment user reservation attempts
   */
  reservationAttempt = (title, cardnumber) => {
    const date = new Date();
    const date_formatted =
      '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
    this.afs
      .collection('admin')
      .doc('counters')
      .collection('reservation')
      .doc(date_formatted)
      .set({ count: firebase.firestore.FieldValue.increment(1) })
      .then(() => analytics.logEvent('reservation', { title, cardnumber }));
  };
}

result-matching ""

    No results matching ""