Coder Social home page Coder Social logo

yusufugurozbek / angular-google-analytics-example Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 2.0 106 KB

Easy implementation Google Analytics tracking code for Angular 5. It is with Global Site Tag (gtag.js)!

License: MIT License

TypeScript 68.32% JavaScript 21.52% HTML 9.51% CSS 0.65%
gtags angular-google-analytics google-analytics angular angular5 angular-5 angular-cli gtag analytics

angular-google-analytics-example's People

Contributors

yusufugurozbek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular-google-analytics-example's Issues

Not so much an issue but maybe an improvement

Hi,

Firstly big thanks, this really helped me to sort my gtag issue with how to set the url from angular. :-)

I assume that you have used a script file so you can easily access the gtag function.
One syntax i've found that can make this simpler is to use the following :
(<any>window)
This means that the whole code can exist inside the app.component.ts like so:

if (event instanceof NavigationStart) {
   const url = event['url'];
   if (url !== null && url !== undefined && url !== '' && url.indexOf('null') < 0) {
      (<any>window).gtag('config',` environment.googleAnalyticsID , { 'page_path': url });
   }
}

Just wanted to share in case you weren't aware (oh also you might notice i'm using an environment variable as a bit of syntactical sugar).

Thanks again, much appreciated.

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.