LoginSignup
5
5

More than 5 years have passed since last update.

GAでandroid api levelごとにセッションの割合を計算するブックマークレット

Last updated at Posted at 2016-07-04

Android dashboardで見れるのは世界的なシェアで、すでに稼働しているサービスでminSdkVersionを切り上げるなどの場合は実際のそのサービスでのバージョンごとのシェアをみたいところ。

そこで、GAで見れるバージョンごごとのセッション数の割合を計測するブックマークレットを作ってみました。以下のスクリプトをブックマークレットとして登録して

javascript:function toApiVersion(versionName) { switch (versionName) { case '2.3': case '2.3.1': case '2.3.2': return 9; case '4.0.0': case '4.0.1': case '4.0.2': return 14; case 'N': case 'NMR1': return 24; } var versionNum = parseFloat(versionName); switch (versionNum) { case 2.1: return 7; case 2.2: return 8; case 2.3: return 10; case 3.0: return 11; case 3.1: return 12; case 3.2: return 13; case 4.0: return 15; case 4.1: return 16; case 4.2: return 17; case 4.3: return 18; case 4.4: return 19; case 5.0: return 21; case 5.1: return 22; case 6.0: return 23; } return 0; } var tds = $.merge($('.ID-dimension-data10'), $('.ID-dimension-data-0')); var apiVersionMap = []; tds.each(function (_, td) { var apiVersion = toApiVersion(td.innerText); var sessions = $(td).siblings()[2].innerText; var sessionsRatio = /(\d+\.\d+)%/.exec(sessions)[1]; if (!apiVersionMap[apiVersion]) { apiVersionMap[apiVersion] = 0; } apiVersionMap[apiVersion] += +sessionsRatio; }); var acc = 0.0; for (var apiVersion = 7; apiVersion <= 24; apiVersion++) { if (apiVersionMap[apiVersion]) { acc += apiVersionMap[apiVersion]; console.log('apiVersion %d: %.02f (acc. %.02f)', apiVersion, apiVersionMap[apiVersion], acc); } }

GAのサイドメニューの Audience -> Devices and Network -> Devices を開き

Screen Shot 2016-07-04 at 13.29.26.png

さらに Operating System -> Android と進むとバージョンの内訳を見れるので、そこで Show rows を100くらいにしてこのブックマークレットを起動します。

すると、dev consoleにapiVersionごとのセッションのシェアとそのバージョンまでの累計シェアを表示します。

私の趣味のアプリだとたとえばこんな感じでした(2016/7/4 現在)。acc.が累計の割合(%)です。

apiVersion 16: 0.54 (acc. 0.54)
apiVersion 17: 4.62 (acc. 5.16)
apiVersion 18: 0.88 (acc. 6.04)
apiVersion 19: 15.34 (acc. 21.38)
apiVersion 21: 39.03 (acc. 60.41)
apiVersion 22: 12.42 (acc. 72.83)
apiVersion 23: 27.17 (acc. 100)

セッションベースなので実際の端末の状況とは微妙にずれがあるかもしれませんが、minSdkVersion改訂の参考にはなるのではないでしょうか。

bookmarkletの元ソースはこちら:

function toApiVersion(versionName) {
    switch (versionName) {
        case '2.3':
        case '2.3.1':
        case '2.3.2':
            return 9;
        case '4.0.0':
        case '4.0.1':
        case '4.0.2':
            return 14;
        case 'N':
        case 'NMR1':
            return 24;
    }
    var versionNum = parseFloat(versionName);
    switch (versionNum) {
        case 2.1:
            return 7;
        case 2.2:
            return 8;
        case 2.3:
            return 10;
        case 3.0:
            return 11;
        case 3.1:
            return 12;
        case 3.2:
            return 13;
        case 4.0:
            return 15;
        case 4.1:
            return 16;
        case 4.2:
            return 17;
        case 4.3:
            return 18;
        case 4.4:
            return 19;
        case 5.0:
            return 21;
        case 5.1:
            return 22;
        case 6.0:
            return 23;
    }
    return 0;
}

var tds = $.merge($('.ID-dimension-data10'), $('.ID-dimension-data-0'));
var apiVersionMap = [];
tds.each(function (_, td) {
    var apiVersion = toApiVersion(td.innerText);
    var sessions = $(td).siblings()[2].innerText;
    var sessionsRatio = /(\d+\.\d+)%/.exec(sessions)[1];
    if (!apiVersionMap[apiVersion]) {
        apiVersionMap[apiVersion] = 0;
    }
    apiVersionMap[apiVersion] += +sessionsRatio;
});
var acc = 0.0;
for (var apiVersion = 7; apiVersion <= 24; apiVersion++) {
    if (apiVersionMap[apiVersion]) {
        acc += apiVersionMap[apiVersion];
        console.log('apiVersion %d: %.02f (acc. %.02f)', apiVersion, apiVersionMap[apiVersion], acc);
    }
}

なお、Chromeでのみ動作確認しています。

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