Giter Club home page Giter Club logo

ng-log-gtag's Introduction

Angular Google Analytics Integration for NG-LOG

GitHub Actions Status Azure Pipelines Status codecov npm version Gitter

Google Analytics Global Site Tag gtag.js integration of DagonMetric/ng-log for Angular applications.

Getting Started

Add the global site tag

Add gtag.js to your site, see instruction from developers.google.com/analytics/devguides/collection/gtagjs.

Installation

npm

npm install @dagonmetric/ng-log @dagonmetric/ng-log-gtag

or yarn

yarn add @dagonmetric/ng-log @dagonmetric/ng-log-gtag

Module Setup (app.module.ts)

import { LogModule } from '@dagonmetric/ng-log';
import { GTagLoggerModule } from '@dagonmetric/ng-log-gtag';

@NgModule({
  imports: [
    // Other module imports

    // ng-log modules
    LogModule,
    GTagLoggerModule.withOptions({
      measurementId: 'GA_MEASUREMENT_ID'
    })
  ]
})
export class AppModule { }

Live edit app.module.ts in stackblitz

Usage (app.component.ts)

import { Component, OnInit } from '@angular/core';

import { LogService } from '@dagonmetric/ng-log';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  constructor(private readonly logService: LogService) { }

  ngOnInit(): void {
    // Track traces
    this.logService.trace('Testing trace');
    this.logService.debug('Testing debug');
    this.logService.info('Testing info');
    this.logService.warn('Testing warn');

    // Track exceptions
    this.logService.error(new Error('Testing error'));
    this.logService.fatal(new Error('Testing critical'));

    // Track page view
    this.logService.trackPageView({
      name: 'My Angular App',
      uri: '/home'
    });

    // Track page view with timing
    this.logService.startTrackPage('about');
    this.logService.stopTrackPage('about', { uri: '/about' });

    // Track custom event
    this.logService.trackEvent({
      name: 'video_auto_play_start',
      properties: {
        non_interaction: true
      }
    });

    // Track custom event with metrics
    this.logService.trackEvent({
      name: 'foo',
      custom_map: {
        dimension2: 'age',
        metric5: 'avg_page_load_time'
      },
      measurements: {
        avg_page_load_time: 1
      },
      properties: {
        age: 12
      }
    });

    // Track custom event with timing
    this.logService.startTrackEvent('video_auto_play');
    this.logService.stopTrackEvent('video_auto_play', {
      properties: {
        non_interaction: true
      }
    });

    // Set user properties
    this.logService.setUserProperties('<Authenticated User Id>', '<Account Id>');

    // Clear user properties
    this.logService.clearUserProperties();
  }
}

Live edit app.component.ts in stackblitz

Samples

Related Projects

Feedback and Contributing

Check out the Contributing page.

License

This repository is licensed with the MIT license.

ng-log-gtag's People

Contributors

dagonmetric-contributor avatar mmzliveid avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mmzliveid

ng-log-gtag's Issues

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @types/jasminewd2 to ^2.0.13
  • Update dependency @types/node to ^16.18.97
  • Update dependency eslint-plugin-prettier to ^4.2.1
  • Update dependency jasmine-core to ^4.6.0
  • Update dependency prettier to ^2.8.8
  • Update dependency rxjs to ^7.8.1
  • Update dependency tslib to ~2.6.2
  • Update dependency zone.js to ^0.14.6
  • Update dependency @types/jasmine to v5
  • Update dependency @types/node to v20
  • Update dependency eslint to v9
  • Update dependency eslint-config-prettier to v9
  • Update dependency eslint-plugin-jsdoc to v48
  • Update dependency eslint-plugin-prettier to v5
  • Update dependency jasmine-core to v5
  • Update dependency prettier to v3
  • Update dependency typescript to v5
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @angular/common ^11.2.14
  • @angular/core ^11.2.14
  • @dagonmetric/ng-log ^2.3.3
  • rxjs ^7.5.4
  • tslib ~2.3.1
  • @angular-devkit/build-angular ^12.2.16
  • @angular/cli ^11.2.18
  • @angular/compiler ^11.2.14
  • @angular/compiler-cli ^11.2.14
  • @angular/language-service ^11.2.14
  • @angular/platform-browser ^11.2.14
  • @angular/platform-browser-dynamic ^11.2.14
  • @types/jasmine ^3.10.3
  • @types/jasminewd2 ^2.0.10
  • @types/node ^16.11.26
  • @typescript-eslint/eslint-plugin ^4.33.0
  • @typescript-eslint/parser ^4.33.0
  • eslint ^7.32.0
  • eslint-config-prettier ^7.2.0
  • eslint-plugin-jsdoc ^37.9.4
  • eslint-plugin-prettier ^4.0.0
  • jasmine-core ^4.0.1
  • lib-tools ^2.0.4
  • prettier ^2.5.1
  • protractor ~7.0.0
  • ts-node ^10.5.0
  • tsickle ^0.39.1
  • typescript 4.1.5
  • zone.js ^0.11.4
samples/demo-app/package.json
  • @angular/animations 11.2.14
  • @angular/common ^11.2.14
  • @angular/compiler 11.2.14
  • @angular/core ^11.2.14
  • @angular/forms ^11.2.14
  • @angular/platform-browser ^11.2.14
  • @angular/platform-browser-dynamic ^11.2.14
  • @angular/router ^11.2.14
  • @dagonmetric/ng-log ^2.3.3
  • @dagonmetric/ng-log-gtag ^2.3.2
  • rxjs ^7.5.4
  • tslib ~2.3.1
  • zone.js ^0.11.4
  • @angular-devkit/build-angular ^12.2.16
  • @angular/cli ^11.2.18
  • @angular/compiler-cli ^11.2.14
  • @angular/language-service ^11.2.14
  • @types/node ^16.11.26
  • ts-node ~10.5.0
  • typescript ~4.1.5

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.