LoginSignup
7
8

More than 5 years have passed since last update.

マストドンにGoogle Analyticsを導入する

Last updated at Posted at 2017-04-21

はじめに

2017年4月現在、話題のマストドンですが、
中身がrubyやhamlなどで、私にはサッパリ分かりませんでした。

それでもインスタンス運営のために情報収集したいので、
Google Analyticsを導入してみました。

以下、その軌跡です。

(0) 前提

私は、こちらのガイドのとおりに作成しました。
とても感謝です。
http://jtwp470.hatenablog.jp/entry/2017/04/15/174036

(1) Google Analyticsに登録する

むずかしいことなく登録できます。
トラッキングコードをGETしましょう。
https://analytics.google.com/

(2) Javascriptを埋め込む

下記のように、中段あたりにjavascriptを埋め込みましょう。
YOUR TRACKING CODE HERE!!!を(1)でGETしたトラッキングコードに置換することを忘れずに。

~/mastodon/app/views/home/index.html.haml
- content_for :header_tags do
  %script#initial-state{:type => 'application/json'}!= json_escape(render(file: 'home/initial_state', formats: :json))

  = javascript_include_tag 'application', integrity: true, crossorigin: 'anonymous'

  :javascript
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
    ga('create', 'YOUR TRACKING CODE HERE!!!', 'auto');
    ga('send', 'pageview');

= react_component 'Mastodon', default_props, class: 'app-holder', prerender: false

(3) リビルドし再起動する

エラーが出たら(2)を見直してください。

docker-compose build
docker-compose up -d

(4) ダッシュボードを確認する

あとは、Google Analyticsのページで色々チェックするだけです。
https://analytics.google.com/analytics/web/

がんばれ、インスタンス管理者たち!
以上です。

7
8
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
7
8