Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@classi/ngx-google-analytics
Advanced tools
`@classi/ngx-google-analytics` はAngularアプリケーションとGoogle Analytics API(`gtag.js`)間の橋渡しをするためのライブラリです。
@classi/ngx-google-analytics
はAngularアプリケーションとGoogle Analytics API(gtag.js
)間の橋渡しをするためのライブラリです。
[clAnalyticsOn]
ディレクティブによるDOMイベントのトラッキング# install the package
$ npm i @classi/ngx-google-analytics
# install peer dependencies
$ npm i -D @types/gtag.js
@classi/ngx-google-analytics
は window.gtag
変数に依存しています。
公式ガイドに従ってgtag.jsをセットアップしてください: https://developers.google.com/analytics/devguides/collection/gtagjs
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
[!TIP] グローバル関数の名前を変更している場合は、後述のプロバイダー設定で独自の
gtagResolver
を設定できます。
@classi/ngx-google-analytics
の機能を利用するためにアプリケーションへプロバイダーを追加します。
import { ApplicationConfig } from '@angular/core';
import { provideGoogleAnalytics } from '@classi/ngx-google-analytics';
export const appConfig: ApplicationConfig = {
providers: [
provideGoogleAnalytics({ /** custom config **/ }),
],
};
AnalyticsTrackerConfig
オプションdisableTracking?: boolean
: トラッキングを無効化します。開発環境で利用します。デフォルトでは false
です。startTrackingOnInit?: boolean
: アプリケーションの初期化時に自動的にトラッキングを開始する。デフォルトでは false
です。enableVirtualPageViewTracking?: boolean
: ルーターイベントを利用して仮想ページビューをトラッキングする。デフォルトでは false
です。gtagResolver?: GtagResolveFn
: gtag
関数を解決する関数を指定します。デフォルトでは window.gtag
を参照します。[!WARNING] GA4ではシングルページアプリケーションであっても
page_view
イベントを自動的に送信するため、基本的には仮想ページビューイベントを使用する必要はありません。手動でページビューを送る必要がある場合は、2重計測を防ぐために自動ページビュー計測を無効にする必要があります。 自動ページビュー計測を無効化するには、
gtag
スニペットのconfig
にsend_page_view
パラメータを追加します。
gtag('config', 'GA_MEASUREMENT_ID', { send_page_view: false });
詳しくは公式ドキュメントを参照してください: https://developers.google.com/analytics/devguides/collection/ga4/views?hl=ja&client_type=gtag#manual_pageviews
@classi/ngx-google-analytics
は AnalyticsTracker
クラスを提供します。これを利用してトラッキングを行います。
startTracking()
[!IMPORTANT] >
startTrackingOnInit: true
を設定していれば、このステップは省略できます。
トラッキングを開始するまではGoogle Analyticsへのイベント送信は行われません。通常、トラッキングを開始するのに最適な場所は AppComponent
のコンストラクタです。
export class AppComponent {
constructor(private readonly analytics: AnalyticsTracker) {
this.analytics.startTracking();
}
}
setUserContext(user)
/ clearUserContext()
export class AppComponent {
constructor(private readonly analytics: AnalyticsTracker) {
this.analytics.startTracking();
}
setUser(userId: string) {
this.analytics.setUserContext({ id: userId });
this.analytics.clearUserContext();
}
}
setUserProperties(properties)
export class AppComponent {
constructor(private readonly analytics: AnalyticsTracker) {
this.analytics.startTracking();
}
setUserProperties() {
this.analytics.setUserProperties({
custom_property: 'value',
});
}
}
sendEvent(event)
export class AppComponent {
constructor(private readonly analytics: AnalyticsTracker) {
this.analytics.startTracking();
}
sendCustomEvent() {
this.analytics.sendEvent({
name: 'click',
// optional
params: {
event_category: 'test',
event_label: 'foobar',
value: 100,
},
});
}
}
AnalyticsOnDirective
: <button clAnalyticsOn>
単一のDOMイベントとイベントトラッキングをバインドするディレクティブです。GoogleAnalyticsModule
をインポートして利用できます。
@Component({
standalone: true,
imports: [GoogleAnalyticsModule],
template: `<button clAnalyticsOn="click" [analyticsEvent]="clickEvent">Buy</button>`,
})
export class SomeComponent {
clickEvent = {
name: 'click',
params: {
event_category: 'test',
event_label: 'foobar',
value: 100,
},
};
}
clAnalyticsOn="{{eventName}}"
: トラッキングするDOMイベント名を指定します。[analyticsEvent]="event"
: Google Analyticsに送信するイベントオブジェクトを設定します。詳細は sendEvent
ドキュメントを参照してください。FAQs
`@classi/ngx-google-analytics` はAngularアプリケーションとGoogle Analytics API(`gtag.js`)間の橋渡しをするためのライブラリです。
We found that @classi/ngx-google-analytics 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.