このページでは

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

Hotjar

Hotjarは、ユーザーに行動分析とフィードバックデータを提供するプロダクト体験インサイトツールです。

連携を設定する

Hotjar プラグインの設定

イベントをHotjarに転送するには、Amplitude送信先プラグインのバリアントを使用してください。以下のテンプレートは、Hotjar用に設計された送信先プラグインです。このプラグインは、Hotjar ブラウザ追跡コードのインスタンスを作成し、Amplitude の SDK から追跡されたイベントを転送します。 このテンプレートはあらゆるニーズに合わせてカスタマイズできます。

ts
import { BrowserConfig, DestinationPlugin, Event, PluginType, Result } from '@amplitude/analytics-types';
import { default as hj } from '@hotjar/browser';
export class HotjarPlugin implements DestinationPlugin {
  name = 'hotjar';
  type = PluginType.DESTINATION as const;
  siteId: number;
  hotjarVersion: number;
  constructor(siteId: number, hotjarVersion: number) {
    this.siteId = siteId;
    this.hotjarVersion = hotjarVersion;
  }
  async setup(): Promise<void> {
    hj.init(this.siteId, this.hotjarVersion);
  }
  async execute(event: Event): Promise<Result> {
    if (event.event_type === '$identify') {
      const { user_id, device_id, user_properties } = event;
      const hotjarId = user_id || device_id || '';
      hj.identify(hotjarId, user_properties || {});
    } else {
      hj.event(event.event_type);
    }
    return {
      code: 0,
      event: event,
      message: 'Event forwarded to Hotjar API',
    };
  }
}

Amplitudeプラグインの使用状況

アプリのコードでプラグインをインポートし、Amplitude SDKインスタンスに追加します。

ts
import * as amplitude from '@amplitude/analytics-browser';
import { HotjarPlugin } from './HotjarPlugin';
amplitude.init(AMPLITUDE_API_KEY);
amplitude.add(new HotjarPlugin(HOTJAR_SIDE_ID, HOTJAR_VERSION));
amplitude.logEvent('open app');

これは役に立ちましたか?