//tips
//Unity analyticsでsnsシェアクリック数値を記録する
Unity Analyticsを使用して、snsのシェアを数値として把握できるようにする。
AnalyticsEventクラスのメソッドを使って標準イベントを実装する。
https://note.com/npaka/n/n5368b72842f2
https://docs.unity3d.com/ja/2019.4/Manual/UnityAnalyticsStandardEvents.html
ad設定と同じく、Window → General → Servicesから選択画面表示。
Cannot ennoble analyticsと表示された場合は、一度unityを閉じて再度ログインして設定することで、無事に問題は解決した。
https://forum.unity.com/threads/cannot-enable-analytics.389330/
https://docs.unity3d.com/Manual/UnityAnalyticsSetup.html
スクリプトで全てを設定する必要はなく、Analytics Event Trackerコンポーネントを使用できる。
https://docs.unity3d.com/ja/2019.4/Manual/class-AnalyticsEventTracker.html
下記の動画説明が大変わかりやすかった。
現状ではAnalytics Library 3.2.2を併用しないと、 Analytics Event Trackerコンポーネントは出てこないよう。
https://forum.unity.com/threads/cant-see-analytics-event-tracker-component.753128/
また、現在ではスクリプトでAnalytics Event Trackerを記載することが主流のよう。
https://forum.unity.com/threads/no-analytics-event-tracker.878788/
https://docs.unity3d.com/ScriptReference/Analytics.Analytics.CustomEvent.html
https://docs.unity3d.com/Manual/UnityAnalyticsStandardEvents.html
https://qiita.com/dotcat/items/16c3b192539652b5a77a
一旦下記のスクリプトをshareボタンにアタッチしてdebugしたところconsoleへの反応はきちんと返ってくる。
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics;
public class Analyticstest : MonoBehaviour
{
public void OnGameOver()
{
Debug.Log("ongameover");
int totalPotions = 5;
int totalCoins = 100;
Analytics.CustomEvent("gameOver", new Dictionary<string, object>
{
{ "potions", totalPotions },
{ "coins", totalCoins }
});
}
}
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics;
public class snsAnalytics : MonoBehaviour
{
int share = 0;
public void Pushsns()
{
share += 1;
Analytics.CustomEvent("sns-share", new Dictionary<string, object>
{
{ "share", share },
});
}
}
一方で、unity起動時およびiPhone起動時ともunity dashbord内analyticsのデータエクスプローラーの項目にcustomEventの項目が表示されない。
これは6時間後に反映されるとのこと。
https://forum.unity.com/threads/how-to-check-unity-analytics-is-working-without-th-validator.813507/
https://forum.unity.com/threads/unity-analytics-validator-problem.707489/
ちなみにvalidatorは現在のunityでは削除されているとのこと。
きちんと機能しているか確認するためにAnalyticsResultを使用する。
https://forum.unity.com/threads/removal-of-validator-and-livestream-features-on-january-16th.810150/?_ga=2.207953042.1274329806.1601340782-2033702608.1599282529
https://forum.unity.com/threads/removal-of-validator-and-livestream-features-on-january-16th.810150/?_ga=2.207953042.1274329806.1601340782-2033702608.1599282529