Giter Site home page Giter Site logo

angulartics / angulartics2 Goto Github PK

View Code? Open in Web Editor NEW
1.0K 34.0 193.0 3.55 MB

Vendor-agnostic analytics for Angular2 applications.

License: MIT License

JavaScript 0.49% TypeScript 96.22% HTML 2.39% SCSS 0.89%
angular angular2 google-analytics angulartics2 analytics piwik baidu-analytics google-tag-manager mixpanel kissmetrics

angulartics2's Introduction

angulartics2

NPM version NPM downloads Build Status MIT license

Gitter Chat

Vendor-agnostic Analytics for Angular Applications. angulartics.github.io/angulartics2

Dependencies

Latest version available for each version of Angular

Angulartics2 Angular
8.3.0 8.x
9.1.0 9.x
10.1.0 10.x
11.0.0 12.x
latest 13.x

Installation

npm install angulartics2 --save

Include it in your application

  1. Add Angulartics2Module to your root NgModule passing any options desired
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';

import { Angulartics2Module } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2';

const ROUTES: Routes = [
  { path: '',      component: HomeComponent },
  { path: 'about', component: AboutComponent },
];

@NgModule({
  imports: [
    BrowserModule,
    RouterModule.forRoot(ROUTES),

    // added to imports
    Angulartics2Module.forRoot(),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})

Note the different imports when Using Without A Router or Using With UI-Router.

  1. Required: Import your providers in the root component. Call startTracking() to start the tracking of route changes.
// component
import { Angulartics2GoogleAnalytics } from 'angulartics2';

@Component({  ...  })
export class AppComponent {
  constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {
    angulartics2GoogleAnalytics.startTracking();
  }
}

Usage

Tracking events in templates/HTML

To track events you can inject the directive angulartics2On into any component and use the attributes angulartics2On, angularticsAction and angularticsCategory:

// component
import { Component } from '@angular/core';

@Component({
  selector: 'song-download-box',
  template: `
    <div 
      angulartics2On="click" 
      angularticsAction="DownloadClick" 
      [angularticsCategory]="song.name">
      Click Me
    </div>
  `,
})
export class SongDownloadBox {}

import { NgModule } from '@angular/core';
import { Angulartics2Module } from 'angulartics2';

@NgModule({
  imports: [
    Angulartics2Module,
  ],
  declarations: [
    SongDownloadBox,
  ]
})

If you need event label, you can use

<div 
  angulartics2On="click" 
  angularticsAction="DownloadClick" 
  angularticsLabel="label-name" 
  angularticsValue="value" 
  [angularticsCategory]="song.name" 
  [angularticsProperties]="{'custom-property': 'Fall Campaign'}">
  Click Me
</div>

Tracking events in the code

import { Angulartics2 } from 'angulartics2';

constructor(private angulartics2: Angulartics2) {
  this.angulartics2.eventTrack.next({ 
    action: 'myAction', 
    properties: { category: 'myCategory' },
  });
}

If you need event label, you can use

this.angulartics2.eventTrack.next({ 
  action: 'myAction',
  properties: { 
    category: 'myCategory', 
    label: 'myLabel',
  },
});

Configuring the Module

Exclude routes from automatic pageview tracking

Pass string literals or regular expressions to exclude routes from automatic pageview tracking.

Angulartics2Module.forRoot({
  pageTracking: {
    excludedRoutes: [
      /\/[0-9]{4}\/[0-9]{2}\/[a-zA-Z0-9|\-]*/,
      '2017/03/article-title'
    ],
  }
}),

Remove IDs from url paths

/project/12981/feature becomes /project/feature

Angulartics2Module.forRoot({
  pageTracking: {
    clearIds: true,
  }
}),

By default, it removes IDs matching this pattern (ie. either all numeric or UUID) : ^\d+$|^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$.

You can set your own regexp if you need to :

/project/a01/feature becomes /project/feature

Angulartics2Module.forRoot({
  pageTracking: {
    clearIds: true,
    idsRegExp: new RegExp('^[a-z]\\d+$') /* Workaround: No NgModule metadata found for 'AppModule' */
  }
}),

Remove Query Params from url paths

This can be combined with clearIds and idsRegExp

/project/12981/feature?param=12 becomes /project/12981/feature

Angulartics2Module.forRoot({
  pageTracking: {
    clearQueryParams: true,
  }
}),

Remove Hash from url paths

/callback#authcode=123&idToken=456 becomes /callback

Angulartics2Module.forRoot({
  pageTracking: {
    clearHash: true,
  }
}),

Using Without A Router

Warning: this support is still experiemental
@angular/router must still be installed! However, it will not be used.

import { Angulartics2RouterlessModule } from 'angulartics2';
@NgModule({
  // ...
  imports: [
    BrowserModule,
    Angulartics2RouterlessModule.forRoot(),
  ],
})

Using With UI-Router

Warning: this support is still experiemental
@angular/router must still be installed! However, it will not be used.

import { Angulartics2UirouterModule } from 'angulartics2';
@NgModule({
  // ...
  imports: [
    BrowserModule,
    Angulartics2UirouterModule.forRoot(),
  ],
})

SystemJS

Using SystemJS? If you aren't using defaultJSExtensions: true you may need to use:

System.config({
    packages: {
        "/angulartics2": {"defaultExtension": "js"},
    },
});

Supported providers

For other providers

If there's no Angulartics2 plugin for your analytics vendor of choice, please feel free to write yours and PR it!

Minimal setup for Google Analytics

Contributing

Please see the CONTRIBUTING and CODE_OF_CONDUCT files for guidelines.

License

MIT

Related Projects

  • analytics-angular: Write analytics code once, collect customer data from any source, and send it to over 250+ destinations with Segment.

angulartics2's People

Contributors

batista avatar hacklone avatar hikirsch avatar janexner avatar janpio avatar jess6569 avatar jonnybgod avatar kwv avatar mewis avatar nathanwalker avatar nicholascelestin avatar npoirey avatar pankas87 avatar patrickmichalina avatar rnsoon avatar roldengarm avatar roman-lo avatar scttcper avatar sebastiannm avatar shahmirn avatar silvan88 avatar skovmand avatar smoke avatar smyth64 avatar srcflux avatar timelf123 avatar tomasklingen avatar tproenca avatar trippmartin avatar tydanielson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angulartics2's Issues

Installing in Travis fails due to postinstall script

Hey,
I installed the library locally and everything seemed to work fine.
However, when running my build in Travis i get an error due to angulartics2 postinstall script:
screen shot 2016-04-10 at 20 36 55

I checked the package.json and typings seems to point to the index file. Is this correct?

Thank you

_gaq not defined

Get an Uncaught ReferenceError: _gaq is not defined. (I'm using the new analytics.js code so I wouldn't expect it to be.)

The culprit is at line 30 of the compiled code

 Angulartics2GoogleAnalytics.prototype.pageTrack = function (path) {
 if (_gaq) {
   _gaq.push(['_trackPageview', path]);
  ...

Easy fix was to define var _gaq; in my index.html though something like

   var _gaq = window._gaq || null;
   var ga = window.ga || null;

in the source might be better.

Ionic2 integration

Hi
How well does angulartics 2 integrate with ionic2 which itself relies on angular2?

Support for piwik

It looks like there is no longer support for piwik. Is this in the works or is it no longer to be supported?

Page view not firing

Hi,
got the Angular quickstart RC1 code to run with this code. I can see that events are being captured by Google Analytics however no page views are captured. I am using Google Tag Assistant (on chrome) and I am getting "No HTTP response detected". If I add back the following line "ga('send', 'pageview');" then the page view is captured.

Any suggestions on how to debug this one? could it be due to the use of APP_BASE_HREF?

main.ts

import { bootstrap }    from '@angular/platform-browser-dynamic';
import { AppComponent } from './app.component';
import { Type } from '@angular/common/src/facade/lang';
import {ROUTER_PROVIDERS} from '@angular/router';
import {Angulartics2} from 'angulartics2';
import {APP_BASE_HREF} from '@angular/common';
import {provide} from "@angular/core";
bootstrap(<Type>AppComponent, [ROUTER_PROVIDERS, Angulartics2,provide(APP_BASE_HREF, {useValue : '/' })]);

app.component.ts

import { Component } from '@angular/core';
import {Angulartics2GoogleAnalytics} from 'angulartics2/src/providers/angulartics2-google-analytics';
import {Angulartics2} from 'angulartics2';
import {Angulartics2On} from 'angulartics2';
@Component({
  selector: 'my-app',
  providers: [Angulartics2GoogleAnalytics],
  directives: [Angulartics2On],
  template: '<h1>My First Angular 2 App</h1><input type="button" angulartics2On="click" angularticsEvent="bla" angularticsCategory="test"/>'
})
export class AppComponent {
  constructor(angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {}
}

Thanks,
Lior

build warnings due to source maps referencing missing source files.

I'm using Angulartics2 with a project derived from angular2-webpack-starter and an seeing the following warnings:

`
WARNING in ./~/angulartics2/index.js
Cannot find source file 'src/index.ts': Error: Cannot resolve 'file' or 'directory' ./src/index.ts in path/node_modules/angulartics2

WARNING in ./~/angulartics2/core/angulartics2On.js
Cannot find source file '../src/core/angulartics2On.ts': Error: Cannot resolve 'file' or 'directory' ../src/core/angulartics2On.ts in path/node_modules/angulartics2/core

WARNING in ./~/angulartics2/core/angulartics2.js
Cannot find source file '../src/core/angulartics2.ts': Error: Cannot resolve 'file' or 'directory' ../src/core/angulartics2.ts in path/node_modules/angulartics2/core
`

The warnings appear to come from the source maps, which reference *.ts files that are not included in the package.

angulartics2 Facebook Pixel provider

I am using angulartics2 in my app, and everything was working fine before the last commit "Add
Facebook Pixel provider" 17d2b6b , and now I'm getting these errors :

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\facebook\angulartics2-facebook.d.ts
(3,14): error TS1005: '=' expected.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\facebook\angulartics2-facebook.d.ts
(3,26): error TS1005: ';' expected.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\facebook\angulartics2-facebook.d.ts
(3,14): error TS2304: Cannot find name 'angulartics2'.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\facebook\angulartics2-facebook.d.ts
(3,28): error TS7008: Member 'Angulartics2' implicitly has an 'any' type.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\gtm\angulartics2-gtm.d.ts
(3,14): error TS1005: '=' expected.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\gtm\angulartics2-gtm.d.ts
(3,26): error TS1005: ';' expected.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\gtm\angulartics2-gtm.d.ts
(3,14): error TS2304: Cannot find name 'angulartics2'.

ERROR in D:\Users\sbehbaha\Documents\CALF\front\node_modules\angulartics2\dist\providers\gtm\angulartics2-gtm.d.ts
(3,28): error TS7008: Member 'Angulartics2' implicitly has an 'any' type.

Any idea ?
Thanks in advance

No provider error

I am getting:

ORIGINAL``EXCEPTION: No provider for LocationStrategy! (Angulartics2 -> Location -> LocationStrategy)

Any ideas?

Update to Angular2 rc.1

Any plans on updating to rc.1?

I'm still using router-deprecated because the new router is too unstable, so it would be nice if angulartics2 support both for now.

As far as I peeked in the sources, updating wouldn't be too much trouble.

Can't get it to work with angular quickstart / systemjs

I'm using the angular2 quickstart setup together with ng2-bootstrap. Everything is working and I would love to add angulartics, but I can't get it to work.

These are the errors in my Chrome console:

angulartics2.ts:1Uncaught ReferenceError: require is not defined(anonymous function) @ angulartics2.ts:1
angulartics2-google-analytics.ts:1Uncaught ReferenceError: require is not defined(anonymous function) @ angulartics2-google-analytics.ts:1
angular2-polyfills.min.js:1 Error: SyntaxError: Unexpected token <(…)

In the Network tab both angulartics2.js and angulartics2-google-analytics.js are loading propertly, but then they are loaded again and searched as /angulartics2 and /angulartics2/src/providers/angulartics2-google-analytics and both of them return "Loading..."

I've tried to map "angulartics2": "node_modules/angulartics2" and a bunch of other variations. Strangely I can at most seem to get one of the "Loading..." messages to return depending on my map, but not both..

This is my index.html:

<!doctype html>
<html lang="en">
<head>
  <base href="/">
  <meta charset="UTF-8">
  <title>Angular2 playground</title>

  <link rel="stylesheet" href="css/main.css">

  <!-- 1. Load libraries -->
  <script src="node_modules/es6-shim/es6-shim.min.js"></script>
  <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
  <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>

  <script src="node_modules/angular2/bundles/angular2-polyfills.min.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>
  <script src="node_modules/rxjs/bundles/Rx.min.js"></script>

  <script src="node_modules/angular2/bundles/router.dev.js"></script>
  <script src="node_modules/angular2/bundles/http.dev.js"></script>
  <script src="node_modules/angular2/bundles/angular2.dev.js"></script>

  <script src="node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>

  <script src="node_modules/angulartics2/src/core/angulartics2.js"></script>
  <script src="node_modules/angulartics2/src/providers/angulartics2-google-analytics.js"></script>

  <script>
    System.config({
      packages: {
        app: {
          format: 'register',
          defaultExtension: 'js'
        },
        "node_modules/ng2-bootstrap": {
          "defaultExtension": "js"
        },
        "node_modules/angulartics2": {"defaultExtension": "js"}
      },
      map: {
        'ng2-bootstrap': 'node_modules/ng2-bootstrap',
        moment: 'node_modules/moment/moment.js',
      },
      paths: {
        "ng2-bootstrap/ng2-bootstrap": "node_modules/ng2-bootstrap/ng2-bootstrap",
      }
    });
    System.import('app/main')
            .then(null, console.error.bind(console));
  </script>
</head>

<!-- 3. Display the application -->
<body>
<div class="container">
  <my-app>Loading...</my-app>
</div>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-18982324-19', 'auto');
  //ga('send', 'pageview');
</script>
</body>
</html>

@angular/router 3.0.0 support?

I am having a hell of a time trying to figure out where I am going wrong..

// main.ts
import {Angulartics2} from 'angulartics2';

bootstrap(AppComponent, [
ROUTER_PROVIDERS, HTTP_PROVIDERS, TRANSLATE_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy}), Angulartics2
]).catch(err => console.error(err));

// app.component.ts
import {Angulartics2GoogleAnalytics} from 'angulartics2/src/providers/angulartics2-google-analytics';

@component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: [ROUTER_DIRECTIVES],
pipes: [TranslatePipe],
providers: [Angulartics2GoogleAnalytics]
})

// index.html
ga('create', 'TRACKING_ID_HERE', 'auto');

All of the files are getting loaded appropriately (I can see them loaded within the 'Sources' tab in chrome) but I can't hit any breakpoints within any of these files and no page views are getting tracked (I don't see any requests in the browser or within google analytics).. Am I missing something or is this just not operational with the new angular 2 router? Please let me know if there is any more information I can provide.

EDIT: Make sure you actually inject the components in your AppComponent..

Update to RC5

I don't believe the repository is compatible with RC5.

First pageload is tracked twice

When loading a page, the pageTrack ReplaySubject is firing twice on page load, because the pageTrack.onNext() is invoked twice from the spyRouter()-method in angulartics2.js - once on the setup of the function from the constructor() and once from its subscription to the angular2 router.

For every other route change the pageTrack is only fired once. See this example where the page is reloaded (firing 2 pageTrack events), and then a link is clicked (firing 1 event).

screen shot 2016-03-13 at 12 25 17

This was done by pasting in console.log("Logging GA pageChange", path, location); in the top of the Angulartics2GoogleAnalytics pageTrack-method.

I added a console.log to see where the pageTrack.next() comes from:

screen shot 2016-03-13 at 12 26 34

A pull request is ready with a proposal for a fix.

@angular/compiler-cli - AOT failing for 'Angulartics2On'

C:\Users\da5\Documents\local repo\UST>"./node_modules/.bin/ngc" -p \src
Error: Unexpected value 'Angulartics2On' declared by the module 'AppModule'
at C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler\bundles\compiler.umd.js:14174:33
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler\bundles\compiler.umd.js:14161:51)
at C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler\bundles\compiler.umd.js:12952:58
at Array.forEach (native)
at OfflineCompiler.analyzeModules (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler\bundles\compiler.umd.js:12951:21)
at CodeGenerator.codegen (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler-cli\src\codegen.js:105:47)
at codegen (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler-cli\src\main.js:7:81)
at Object.main (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler-cli\node_modules@angular\tsc-wrapped\src\main.js:30:16)
at Object. (C:\Users\da5\Documents\local repo\UST\node_modules@angular\compiler-cli\src\main.js:14:9)
Compilation failed

Invalid 'reference' directive syntax with 1.1.4

Getting the following error in my typescript (v1.8.10) compilation step for my build process:

node_modules/angulartics2/src/core/angulartics2.d.ts(1,1): error TS1084: Invalid 'reference' directive syntax.

Moving back to 1.1.3 the error is not present

ga basic ecommerce tracking

Would doing a PR for this be useful and what's the best way to add this in; a new provider or add to the existing one?
Thanks

re-publish with "scripts" section removed or at least the 'prepublish' hook

The prepublish hook is problematic when you publish to npm as it causes that hook to run when installing it as a plugin from npm... so it executes "typings install && tsc -d" when installing which is not good. In some cases it doesn't cause problems but in others it does.

Best thing to do would be to just remove that prepublish script, bump the version, then republish, then you can add it back if you need to.

How do you disable tracking?

I have an application that will be deployed in multiple environments. Actual tracking will happen only on one environment. The envrionment that will have tracking will let the app know with a boolean to turn on analytics. How can I get this plugin to disable analytics based on an external variable that is passed to the application?

Working Router agnostic now, hooray! But, one thing..

So it looks like location.subscribe does fire on first load of the page so you get the initial page track which is awesome.

However, subsequent route changes do not fire through location.subscribe.
We can either:

A. suggest that users subscribe to whichever router they are using and track events manually themselves for route changes.
B. try to figure out how to get Location wired up correctly to react to route/location changes
C. B may be hindered by a framework bug, not sure. It seems like location.subscribe should pick up any url changes, but it doesn't appear so. We could wait until this is fixed, post issue on angular repo, and get some clarity on how to do this best (without a router in the mix) with just Location.

I'm still thinking about what the best way forward is.

At any rate, the latest release does work to track all events properly (and even the initial page load tracking) and works without any dependency on any particular router which is awesome.

angulartics2 event does not work

Originally asked on Stack Overflow.


import { Component } from '@angular/core';
import { Angulartics2On } from 'angulartics2';

@Component({
  selector: 'random-component',
  directives: [Angulartics2On],
  template: `
    <button angulartics2On angularticsEvent="Play" angularticsCategory="Videos" (click)="onClick()">Play</button>
  `
})
export class RandomComponent {
  onClick() {
    console.log('Hi');
  }
}

does not work for me. The effect does not show in the Google Analytics Debugger and Google Analytics Real-Time reports.

What may cause this? Thanks

Using without router?

Is there any way to use this library without the angular 2 router? My application doesn't make use of this router and I'm finding myself bringing it in to my project just to keep from getting 'No provider for Location' and 'no provider for Router' errors from angular. I would prefer not to have to do this if possible.

Getting module not found errors @ 1.0.10

Hey,

Getting these module not found errors on a fresh install. Is this a peerdep thing perhaps? Thanks!

ERROR in ./~/angulartics2/src/core/angulartics2.js
Module not found: Error: Cannot resolve module 'rxjs/ReplaySubject' in <path>/node_modules/angulartics2/src/core
 @ ./~/angulartics2/src/core/angulartics2.js 12:22-51

ERROR in ./~/angulartics2/src/core/angulartics2.js
Module not found: Error: Cannot resolve module 'angular2/platform/common' in <path>/node_modules/angulartics2/src/core
 @ ./~/angulartics2/src/core/angulartics2.js 14:15-50

Update to RC-4

Is there any plans to update it to RC-4? I guess there shouldn't be any breaking changes.

Cordova app

Hi,

Any one has any expeirent with Cordova?

After reading the web this line should make it work:

ga('set', 'checkProtocolTask', null);

However, I'm not sure if it actually is working. any one has any experience with this?

How to trigger an event from a component

Hi, I have a question

It is explained how to use a directive to attach a event to a button click, but how do I trigger an event in my component. I want to write something like this:

this._angulartics2.eventTrack('click', 'DownloadClick', 'song.name');

But I don't know what the parameters are or how this is supposed to be done??

Don't use private Angular imports

In

import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
you've got import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter' which is private import. From RC6 release of Angular it will pretty much impossible to use private imports which means that people won't be able to use this library with RC6. It is currently blocking https://github.com/ng-bootstrap/ng-bootstrap migration.

From what I can see this import is just used for some non-essential utils and could be probably removed.

please let angulartics2On support custom event

Say I have a component, it will create an event @Output() doSomething.

@Component({
  selector: 'random-component',
  template: `Hi`
})
export class CardsComponent {
  @Output() doSomething = new EventEmitter();
}

Then when I use like this:

<random-component
  angulartics2On="doSomething"
  angularticsCategory="Random category"
  angularticsEvent="Random event"
  (doSomething)="doSomething($event)">
</random-component>

angulartics2On won't run.


The most important thing is that once achieving this, it can support 3rd party components.
And it should be able to fix #36

ReferenceError: Can't find variable: _paq

Application under test adds Piwik tracking code asynchronously:

  <!-- Piwik -->
  <script type="text/javascript">
    var _paq = _paq || [];
    _paq.push(['trackPageView']);
    _paq.push(['enableLinkTracking']);
    (function() {
      var u = "http://127.0.0.1/";
      _paq.push(['setTrackerUrl', u + 'piwik.php']);
      _paq.push(['setSiteId', 1]);
      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>
  <noscript>
    <p><img src="//127.0.0.1/piwik.php?idsite=1" style="border:0;" alt="" /></p>
  </noscript>
  <!-- End Piwik Code -->

However tests fail:

PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
  ReferenceError: Can't find variable: _paq
  at C:/Users/X/AppData/Local/Temp/d378f78cf983b2d4caff45d22defb58b.browserify:49748 <- node_modules/angulartics2/src/providers/angulartics2-piwik.js:26:0

Other provider implementations kissmetrics, mixpanel, ga manage the race condition inconsistently.

PR to remove the if (_paq) check and just swallow the ReferenceError is coming.

Angulartics broken in ng2.beta.17/rxjs.beta.6

The hot-off-the-press angular2 2.0.0-beta.17 needs rxjs 5.0.0-beta.6 but rxjs/subject/ReplaySubject seems to have moved to rxjs/ReplaySubject.

I did try hacking the source code, but I made little progress.

Application bootstrap fails when AdblockPlus has tracking disabled

When AdblockPlus is enabled and it's "Disable Tracking" feature is turned on, then the application bootstrap fails.

I get the following errors in my console:

analytics.js:3 GET https://www.google-analytics.com/analytics.js net::ERR_BLOCKED_BY_CLIENT

zone.js?1477305267073:1241 GET http://localhost:5555/node_modules/angulartics2/src/providers/angulartics2-google-analytics.js net::ERR_BLOCKED_BY_CLIENT

(index):48 Error: Error: XHR error loading http://localhost:5555/node_modules/angulartics2/src/providers/angulartics2-google-analytics.js(…) "Error bootstrapping application."

angulartics angulartics2On directive not working with loadChildren routes in angular2.0

I am using angular2.0 for my application

I installed angulartics2 using npm install angulartics2 --save and imported them in the app module. Every thing worked fine. Later, I used lazyloading for one module and now angulartic2On is not working.Following is my code.

//app.module.ts

`import { Angulartics2 } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2/src/providers/angulartics2-google- analytics';
import { BrowserModule } from '@angular/platform-browser';
import {CommonModule} from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
CommonModule,
FormsModule,
HttpModule,
RouterModule,

Angulartics2Module.forRoot(),
AppRouteRoot
],
providers: [
Angulartics2GoogleAnalytics 
],
bootstrap: [AppComponent]
})`

//app.component.ts

` import { Component } from '@angular/core';

import { Angulartics2 } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2/src/providers/angulartics2-google-analytics';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  constructor(angulartics2: Angulartics2, angulartics2GoogleAnalytics:    Angulartics2GoogleAnalytics) {}

 }`

//app.routes.ts

`import { Routes, RouterModule } from '@angular/router';

import {ModuleWithProviders} from '@angular/core';

import {AppComponent} from './app.component';

export const AppRoutes: Routes = [
{ path: '', component: AppComponent},
{ path: 'about', loadChildren : 'app/about/about.module' },
];

export const AppRouteRoot:ModuleWithProviders = RouterModule.forRoot(AppRoutes, { useHash: true });`

//app.component.html

`


{{title}}

button inside app component `

//about.module.ts

`

// import { Angulartics2Module } from 'angulartics2';
// import { Angulartics2GoogleAnalytics } from 'angulartics2/src/providers/angulartics2-google-   analytics';
// import { Angulartics2On } from 'angulartics2/src/core/angulartics2On';
 import { NgModule }       from '@angular/core';
 import { CommonModule } from '@angular/common';
 import { FormsModule} from '@angular/forms';
 import { HttpModule } from '@angular/http';
 import { RouterModule } from '@angular/router';
 import {AboutComponent} from './about.component';

import {AboutRouting} from './about.routes'

  @NgModule({
     declarations: [

    AboutComponent
//  ,
//   Angulartics2On


],
providers: [
    // Angulartics2GoogleAnalytics

],
imports: [
    CommonModule,    

    RouterModule,
    FormsModule,
    HttpModule,

    AboutRouting,
    // Angulartics2Module.forRoot(),
    // Angulartics2On

]
 })
   export default class AboutModule { }`

//about.component.ts

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

@component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit {

constructor() { }

ngOnInit() {
}

}
`

//about.routes.ts

 import { Routes, RouterModule } from '@angular/router';
    import {ModuleWithProviders} from '@angular/core';
    import {AppComponent} from './app.component';
    export const AppRoutes: Routes = [
    { path: '', component: AppComponent},
    { path: 'about', loadChildren : 'app/about/about.module' },
    ];
    export const AppRouteRoot:ModuleWithProviders = RouterModule.forRoot(AppRoutes, { useHash:   true });

//about.component.html

`<p>
  about works!
</p>
<button type="button" (click)="fnTrack()" angulartics2On="click" angularticsEvent="DownloadClick"   angularticsCategory="ABOUT">About   Click</button>`

//package.json

`...

"dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
     "@angular/platform-browser": "2.0.0",
     "@angular/platform-browser-dynamic": "2.0.0",
     "@angular/router": "3.0.0",
    "angulartics2": "^1.1.9",
    "core-js": "^2.4.1",
    "process-nextick-args": "^1.0.7",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
   "zone.js": "^0.6.23"
  }

...`

is there any way to enable angulartics2 in lazy Routing

Thanks in advance

Directive angulartics2O doesn't work with ng2-bootstrap tabs

The events doesn't get fired on the ng2-bootstrap tab. I tried with angulartics2On="click" as well. No luck..

<tabset>   
  <tab heading="Category" (select)="onTabSelect($event)" angulartics2On="select" angularticsEvent="ResultTab" angularticsCategory="'Category'">
      ....
  </tab>
  <tab heading="Time" (select)="onTabSelect($event)" angulartics2On="select" angularticsEvent="ResultTab" angularticsCategory="'Time'">
      ....
  </tab>      
</tabset>

Our example works fine:

<div angulartics2On="click" angularticsEvent="DownloadClick" angularticsCategory="{{ song.name }}"></div>

angular: 2.0.0-rc.1
angulartics2: 1.0.11
ng2-bootstrap: 1.0.16

Thanks, Stefan

Cannot import angulartics2 1.2.0

Hi, I just updated to the latest v 1.2.0 of angulartics2 and am no longer able to import the Module.
Have the import names now changed?

import { Angulartics2Module } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2/src/providers/angulartics2-ga';

How to tracking only production

Hi,

I am using angulartics2 with Angular 2.0.0-rc5 and webpack to track user activities and it works VERY well, and thank you. Only what I want to do is turn GA on when only production environment, not stage or development.

Is there any function or tricks to prevent tracking on stage environment?

Best,

Publish latest when possible?

@JonnyBGod I pushed up beta.16 compatibility to master just a few minutes ago. Since I'm not a collaborator on npm, it may not have bumped/published. If you could do so as soon as possible would be great. Thanks! Trying to update the seed project and need this update.

Error: No provider for location

Hey there,

I followed the instructions in your README.md to install this plugin in my Angular 2 application.

I keep getting this error:

ORIGINAL EXCEPTION: No provider for Location! (Angulartics2 -> Location)

Is it because I'm using ngrx/router instead of angular2/router ?

npm - missing .js files

Looks like with 1.0.3 just published, it's now missing the src/providers/*.js files...
the .js.map files are there but no .js files resulting in errors.
From a fresh install with latest:
screen shot 2016-04-14 at 4 10 04 pm

DI based tracker?

Is there a base tracker class that could be used, so we could use DI to set the specific tracker?

I.e. instead of including Angulartics2GoogleAnalytics everywhere, I'd rather include Angulartics2Analytics and use DI to provide the 'Angulartics2GoogleAnalytics' for the Angulartics2Analytics

That way, I can create analytics-engine agnostic mappings, in my site, and later decide on which tracker to use (or, even better, allow multiple trackers).

return bootstrap(App,
        [
 bind(Angulartics2Analytics).toClass(Angulartics2GoogleAnalytics), etc etc

Then, in my services

 constructor(
        public Angulartics2Analytics : Angulartics2GoogleAnalytics,
). etc etc

I realize, not all trackers support all events, but each driver could then decide how to gracefully synthesize requested behavior or even ignore it.

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.