Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
angulartics2
Advanced tools
Vendor-agnostic Analytics for Angular Applications. angulartics.github.io/angulartics2
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 |
12.0.0 | 13.x |
13.0.0 | 14.x |
latest | 15.x |
npm install angulartics2 --save
Angulartics2Module
to your root NgModule passing any options desiredimport { 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.
startTracking()
to start the tracking of route changes.// component
import { Angulartics2GoogleAnalytics } from 'angulartics2';
@Component({ ... })
export class AppComponent {
constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {
angulartics2GoogleAnalytics.startTracking();
}
}
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>
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',
},
});
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'
],
}
}),
/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' */
}
}),
This can be combined with clearIds and idsRegExp
/project/12981/feature?param=12
becomes /project/12981/feature
Angulartics2Module.forRoot({
pageTracking: {
clearQueryParams: true,
}
}),
/callback#authcode=123&idToken=456
becomes /callback
Angulartics2Module.forRoot({
pageTracking: {
clearHash: true,
}
}),
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(),
],
})
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(),
],
})
Using SystemJS? If you aren't using defaultJSExtensions: true
you may need to use:
System.config({
packages: {
"/angulartics2": {"defaultExtension": "js"},
},
});
analytics.js
)gtag.js
)If there's no Angulartics2 plugin for your analytics vendor of choice, please feel free to write yours and PR it!
analytics.js
gtag.js
gtag.js
Please see the CONTRIBUTING and CODE_OF_CONDUCT files for guidelines.
FAQs
Vendor-agnostic web analytics for Angular2 applications
The npm package angulartics2 receives a total of 28,903 weekly downloads. As such, angulartics2 popularity was classified as popular.
We found that angulartics2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.