LoginSignup
0

More than 5 years have passed since last update.

Angulartics google tag managerのとLaravel

Posted at

これは

angulartics-google-tag-manager
https://github.com/angulartics/angulartics-google-tag-manager
の使いにくい点の回避方法です。

tag manager単体ではangularのroutingに使っているページURLが取れない
なのでこれを入れたいけれどuserIdに関して仕様が合わなくて使いにくい
という事で施した対処です。

userIdではなくuIdを利用する

userIdは動的に勝手にセットしちゃうんだけど、うちのサイトでははじめのページがロードされたタイミングでuser_idはわかっているしclient側でuserIdを意識しない設計なので、ページはじめにロードした時にセットしたdataLayerにセットした値を使いたい。

<script>
    dataLayer = [{
            'uId': '{{Sentry::getUser()->id}}'
    }];
</script>

変数作る

userId:データレイヤー変数のuId

タグに指定している変数を差し替え

「angulartics user id」で指定しているところを「userId」に差し替え

変数消す

importで自動で作成される「angulartics user id」を消す

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
0