npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wizdm/gtag

v1.0.0

Published

Google Tags for Angular

Downloads

59

Readme

Google Tags (Google Analytics) for Angular

Google Tags (also known as Google Analytics) support for Angular.

Installation

Import the Gtag module in your root module calling the static init() function to setup it up:

import { GtagModule } from '@wizdm/gtag';

@NgModule({
  imports: [
    ...
    GtagModule.init({
      targetId: '<<YOUR GOOGLE ID HERE>>'
    })
  ]
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage Example

The package provides a gtag directive to be used ...:

...
<section fxLayout="column" fxLayoutAlign="center center" gtag="home">

  <p><b>Google Site Tagging</b> (aka Google Analytics) Example</p>

</section>
...

The gtag="home" statement in the .html sends a page-view event to the Google Analytics, Google Ads or Google Marketing Platform account you configured during the initialization.

The “home” text will appear in the report to be the page title while the page location is automatically detected by the directive provided the application makes use of a Router.

Sending Tags Programmatically

The package provides GtagService service implementing all the default Google Analytics events:

import { GtagService } from '@wizdm/gtag';
...
@Component(...)
export class MyComponent()

  constructor(private gtag: GtagService) {

    gtag.login('Google');

    gtag.search('Bologna')
      .then( () => console.log('Search correctly tagged') )
      .catch( e => console.error(e) );

    gtag.addToCart([{
      id: "P12345",
      name: "Android Warhol T-Shirt",
      list_name: "Search Results",
      brand: "Google",
      category: "Apparel/T-Shirts",
      variant: "Black",
      list_position: 1,
      quantity: 2,
      price: '2.0'
    }]);
  }
  ...
}
...

The above example demostrates the way to send a login event (with ‘Google’ as its method) a search event (with ‘Bologna’ as a search term) and a complete add_to_cart e-commerce event.

These methods return a Promise, as the search() call made clear, so to perform asynchronous tasks right after the tagging completed.

Timeouts

In order to prevent the Promise from never resolving, in the eventuality the gtag.js library would fail to load, the package implements a timeout function following Google’s recommendations.

The default timeout value is set to 10s and can be configured during initialization.