LoginSignup
2
1

More than 5 years have passed since last update.

SPAのハッシュ付きURL遷移にGTMを仕込む

Posted at

Angularのハッシュ付き遷移を使っているんですが、これだとGoogleAnalyticsのPageViewで / しか取れていないことがわかった。
そこでGoogleタグマネージャを使ってハッシュ付きURLの遷移でもPageViewを取れるようにします。

1. 変数の追加

1.1 hash変数の作成

名前はなんでもいいですが、ここではhashとしました。

変数の種類:JavaScript変数
グローバル変数名:location.hash

スクリーンショット 2018-09-03 19.03.19.png

これを保存します。

1.2 ハッシュ付きトラッキングコードの作成

また名前はなんでもいいです。
GoogleAnalyticsからトラッキングコードを持ってきて入力します。
また、詳細設定>設定するフィールドのpageに先程作成した変数のhashを入れます。

スクリーンショット 2018-09-03 19.12.00.png

これを保存します。

2. トリガーの追加

また名前は(ry

トリガーの種類:履歴の変更
トリガーの発生場所:すべての履歴の変更

スクリーンショット 2018-09-03 19.07.07.png

これを保存します。

3. タグの追加

名前は(ry

以下設定をして、できあがりです。

スクリーンショット 2018-09-03 19.14.15.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1