ngx-analytics
Vendor-agnostic Analytics for Angular Applications. angulartics.github.io/ngx-analytics
- ngx-analytics
Installation
npm install ngx-analytics --save
Include it in your application
- Add
NgxAnalyticsModule
to your root NgModule passing an array of providers to enable
;;; ;; ;
- Required: Import your providers in the root component. This starts the tracking of route changes.
// component;
Usage
Tracking events
To track events you can inject the directive ngx-analyticsOn
into any component and use the attributes ngx-analyticsOn
, angularticsAction
and angularticsCategory
:
// component; ;;
If you need event label, you can use
Click Me
Tracking events in the code
;constructorprivate ngx-analytics: NgxAnalytics
If you need event label
this.ngx-analytics.eventTrack.next;
Exclude routes from automatic pageview tracking
Pass string literals or regular expressions to exclude routes from automatic pageview tracking.
NgxAnalyticsModule.forRoot, ,
Remove ID's from url paths
/project/12981/feature
becomes /project/feature
NgxAnalyticsModule.forRoot, ,
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
NgxAnalyticsModule.forRoot, ,
Remove Query Params from url paths
This can be combined with clearIds and idsRegExp
/project/12981/feature?param=12
becomes /project/12981/feature
NgxAnalyticsModule.forRoot, ,
Using Without A Router
Warning: this support is still experiemental
@angular/router
must still be installed! However, it will not be used.
;
Using With UI-Router
Warning: this support is still experiemental
@angular/router
must still be installed! However, it will not be used.
;
Supported providers
- Google Analytics
- Google Tag Manager
- Google Enhanced Ecom
- Kissmetrics
- Mixpanel
- Piwik
- Segment
- Baidu Analytics
- Facebook Pixel
- Application Insights
- Hubspot
- Adobe Analytics (Omniture)
- Intercom
- Woopra
- Clicky
For other providers
If there's no NgxAnalytics plugin for your analytics vendor of choice, please feel free to write yours and PR' it!
Minimal setup for Google Analytics
To setup Google Analytics add the folowing to main.ts
; if environment.production
you can add other environments if you want. In your environment.prod.ts add the configuration
;
for localhost environments replace 'auto' with 'none'
v4 Migration and Breaking Changes
See Release Notes
SystemJS
Using SystemJS? If you aren't using defaultJSExtensions: true
you may need to use:
System.config;
Contributing
Please see the CONTRIBUTING and CODE_OF_CONDUCT files for guidelines.