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

angular2piwik

v0.1.7-beta

Published

a wrapper to access piwik inside your angular 2 app

Downloads

242

Readme

Angular2Piwik

A small easy to use wrapper component for Piwik to work with your Angular 2 application.

Install through source files

Download directly from github and place the src files in your Angular 2 application.

##npm install

npm install --save angular2piwik

Adding Piwik into your application via Script Tag.

To illustrate the set up, here's the code to inject into your header to initialize Piwik in your application. Piwik's site has the detailed documentation on how to set up communication between Piwik and your application. Make sure you replace the PIWIK_URL with your piwik server. You can remove all the _paq methods in this script and set them up in your Angular 2 application.

<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//{$PIWIK_URL}/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', {$IDSITE}]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Piwik Code -->

Initialize Piwik via Root Component

To enable Piwik via your root component you can now export InitializePiwik provider and inject it in your roop component.

import { Component } from '@angular/core';
import { InitializePiwik } from 'angular2piwik';

@Component({
  selector: 'app',
  providers: [ initializePiwik ],
  template: `<router-outlet></router-outlet>` // Or what your root template is.
})
export class AppComponent {
  constructor(
    private initializePiwik: InitializePiwik
    ) {
      const url = `//*************:*****/anayltics/`; // set your url to whatever should be communicating with Piwik with the correct backslashes
      const id = 2; // Site Id
      initializePiwik.init(url, id);
    }
}

Include it in your application

Bootrapping this application is easy. Import Angular2PiwikModule into your root NgModule.

// bootstrap
 import { NgModule } from '@angular/core';
  import { Angular2PiwikModule } from 'angular2piwik';

  ////
  @NgModule({
    imports :[ Angular2PiwikModule ]
  })

Once that's done you can import ConfigurePiwikTracker and UsePiwikTracker into any component in your application. Always use the configure piwik tracker methods before the use piwik tracker.


// component
import { Component } from '@angular/core';
import { ConfigurePiwikTracker, UsePiwikTracker } from 'angular2piwik';

@Component({
  selector: 'app',
  template: `<router-outlet></router-outlet>` // Or what your root template is.
})
export class AppComponent {
  constructor(
    private configurePiwikTracker: ConfigurePiwikTracker
    private usePiwikTracker: UsePiwikTracker
    ) {
      configurePiwikTracker.setUserId('test-123');
      configurePiwikTracker.setDocumentTitle();
      usePiwikTracker.trackPageView();
    }
}

Tracking events

For now tracking events and actions is manual and is not injected into the html.

<button (click)="whatHappensOnClick(value)"></button>
// component
import { Component } from '@angular/core';
import { UsePiwikTracker } from 'angular2piwik';

@Component({
  selector: 'app',
  templateUrl: './myButton.html'
})
export class AppComponent {
  constructor(
    private usePiwikTracker: UsePiwikTracker
    ) {
    }

    whatHappensOnClick(someVal){
      /*
      * some code...
      */
      usePiwikTracker.trackEvent('clickEvent', {category : 'myClickEvents', label: 'generalClicks', value: someVal})
    }
  
}

Contributing

Please see the CONTRIBUTING and CODE_OF_CONDUCT files for guidelines.

Original Source

All contributers from the source repository have been left in the package.json. It can be viewed here.

License

MIT