Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from yandexmobile/release-2.0.0
Browse files Browse the repository at this point in the history
Update AppMetrica Unity Plugin 2.0.0
  • Loading branch information
bamx23 authored Jan 31, 2017
2 parents f36db13 + 52afc43 commit 5d9ebea
Show file tree
Hide file tree
Showing 46 changed files with 2,456 additions and 1,400 deletions.
4 changes: 2 additions & 2 deletions AppMetrica.unitypackage
Git LFS file not shown
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#AppMetrica - Unity Plugin
# AppMetrica - Unity Plugin

## License
License agreement on use of Yandex AppMetrica for Apps SDK is available at [EULA site] [LICENSE].
License agreement on use of Yandex AppMetrica SDK is available at [EULA site] [LICENSE].

## Documentation
Documentation could be found at [metrica official site] [DOCUMENTATION].
Documentation could be found at [AppMetrica official site] [DOCUMENTATION].

## Changelog

### Version 2.0.0

* Updated native SDKs *(iOS 2.7.0, Android 2.62)*
* Fixed plugin files structure: everything moved into `Assets/AppMetrica`
* Added method for activation configuration updates handling *(for AppMetrica Push SDK Unity Plugin)*

### Version 1.20

* Updated native SDKs *(iOS 2.5.1, Android 2.42)*
Expand Down
237 changes: 114 additions & 123 deletions YandexMetricaPluginSample/Assets/AppMetrica/AppMetrica.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,149 +8,140 @@

public class AppMetrica : MonoBehaviour
{
private class LogEvent
{
public string Condition;
public string StackTrace;
}
[SerializeField]
private string APIKey;

[SerializeField]
private string APIKey;

[SerializeField]
private bool ExceptionsReporting = true;
[SerializeField]
private bool ExceptionsReporting = true;

[SerializeField]
private uint SessionTimeoutSec = 10;
[SerializeField]
private uint SessionTimeoutSec = 10;

#if !APP_METRICA_TRACK_LOCATION_DISABLED
[SerializeField]
private bool TrackLocation = true;
#endif
[SerializeField]
private bool TrackLocation = true;

[SerializeField]
private bool LoggingEnabled = true;

[SerializeField]
private bool HandleFirstActivationAsUpdate = false;

private static bool _isInitialized = false;
private bool _actualPauseStatus = false;

[SerializeField]
private bool LoggingEnabled = true;

private static bool _isInitialized = false;
private ArrayList _handledLogEvents = new ArrayList();
private bool _actualPauseStatus = false;

private static IYandexAppMetrica _metrica = null;
private static object syncRoot = new Object();
public static IYandexAppMetrica Instance
{
get {
if (_metrica == null) {
lock (syncRoot) {
private static IYandexAppMetrica _metrica = null;
private static object syncRoot = new Object ();

public static IYandexAppMetrica Instance {
get {
if (_metrica == null) {
lock (syncRoot) {
#if UNITY_IPHONE || UNITY_IOS
if (_metrica == null && Application.platform == RuntimePlatform.IPhonePlayer) {
_metrica = new YandexAppMetricaIOS();
}
if (_metrica == null && Application.platform == RuntimePlatform.IPhonePlayer) {
_metrica = new YandexAppMetricaIOS ();
}
#elif UNITY_ANDROID
if (_metrica == null && Application.platform == RuntimePlatform.Android) {
_metrica = new YandexAppMetricaAndroid();
}
#endif
if (_metrica == null) {
_metrica = new YandexAppMetricaDummy();
}
}
}
return _metrica;
}
}

void SetupMetrica ()
{
var configuration = new YandexAppMetricaConfig(APIKey) {
SessionTimeout = (int)SessionTimeoutSec,
LoggingEnabled = LoggingEnabled,
};

if (_metrica == null) {
_metrica = new YandexAppMetricaDummy ();
}
}
}
return _metrica;
}
}

void SetupMetrica ()
{
var configuration = new YandexAppMetricaConfig (APIKey) {
SessionTimeout = (int)SessionTimeoutSec,
LoggingEnabled = LoggingEnabled,
HandleFirstActivationAsUpdateEnabled = HandleFirstActivationAsUpdate,
};

#if !APP_METRICA_TRACK_LOCATION_DISABLED
configuration.TrackLocationEnabled = TrackLocation;
if (TrackLocation) {
Input.location.Start ();
}
configuration.TrackLocationEnabled = TrackLocation;
if (TrackLocation) {
Input.location.Start ();
}
#else
configuration.TrackLocationEnabled = false;
#endif

Instance.ActivateWithConfiguration(configuration);
}

private void Awake ()
{
if (!_isInitialized) {
_isInitialized = true;
DontDestroyOnLoad(this.gameObject);
SetupMetrica();
} else {
Destroy(this.gameObject);
}
}

private void Start ()
{
Instance.OnResumeApplication();
}

private void OnEnable ()
{
if (ExceptionsReporting) {
Instance.ActivateWithConfiguration (configuration);
ProcessCrashReports ();
}

private void Awake ()
{
if (!_isInitialized) {
_isInitialized = true;
DontDestroyOnLoad (this.gameObject);
SetupMetrica ();
} else {
Destroy (this.gameObject);
}
}

private void Start ()
{
Instance.OnResumeApplication ();
}

private void OnEnable ()
{
if (ExceptionsReporting) {
#if UNITY_5
Application.logMessageReceived += HandleLog;
Application.logMessageReceived += HandleLog;
#else
Application.RegisterLogCallback(HandleLog);
#endif
}
}
private void OnDisable ()
{
if (ExceptionsReporting) {
}
}

private void OnDisable ()
{
if (ExceptionsReporting) {
#if UNITY_5
Application.logMessageReceived -= HandleLog;
Application.logMessageReceived -= HandleLog;
#else
Application.RegisterLogCallback(null);
#endif
}
}

void OnApplicationPause(bool pauseStatus)
{
if (_actualPauseStatus != pauseStatus) {
_actualPauseStatus = pauseStatus;
if (pauseStatus) {
Instance.OnPauseApplication();
} else {
Instance.OnResumeApplication();
}
}
}

void Update()
{
if (ExceptionsReporting) {
if (_handledLogEvents.Count > 0) {
var eventsToReport = (ArrayList)_handledLogEvents.Clone();
foreach (LogEvent handledLog in eventsToReport) {
Instance.ReportError(handledLog.Condition, handledLog.StackTrace);
_handledLogEvents.Remove(handledLog);
}
}

var reports = CrashReport.reports;
foreach (var report in reports) {
Instance.ReportError(report.text, string.Format("Time: {0}", report.time));
report.Remove();
}
}
}

private void HandleLog(string condition, string stackTrace, LogType type)
{
if (type == LogType.Exception) {
_handledLogEvents.Add(new LogEvent{ Condition = condition, StackTrace = stackTrace });
}
}
}
}

private void OnApplicationPause (bool pauseStatus)
{
if (_actualPauseStatus != pauseStatus) {
_actualPauseStatus = pauseStatus;
if (pauseStatus) {
Instance.OnPauseApplication ();
} else {
Instance.OnResumeApplication ();
}
}
}

public void ProcessCrashReports ()
{
if (ExceptionsReporting) {
var reports = CrashReport.reports;
foreach (var report in reports) {
var crashLog = string.Format ("Time: {0}\nText: {1}", report.time, report.text);
Instance.ReportError ("Crash", crashLog);
report.Remove ();
}
}
}

private void HandleLog (string condition, string stackTrace, LogType type)
{
if (type == LogType.Exception) {
Instance.ReportError (condition, stackTrace);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public abstract class BaseYandexAppMetrica : IYandexAppMetrica
{
private YandexAppMetricaConfig? _metricaConfig;

public event ConfigUpdateHandler OnActivation;

public YandexAppMetricaConfig? ActivationConfig {
get {
return _metricaConfig;
}
}

public virtual void ActivateWithAPIKey (string apiKey)
{
UpdateConfiguration (new YandexAppMetricaConfig (apiKey));
}

public virtual void ActivateWithConfiguration (YandexAppMetricaConfig config)
{
UpdateConfiguration (config);
}

private void UpdateConfiguration (YandexAppMetricaConfig config)
{
_metricaConfig = config;
ConfigUpdateHandler receiver = OnActivation;
if (receiver != null) {
receiver (config);
}
}

public abstract void OnResumeApplication ();

public abstract void OnPauseApplication ();

public abstract void ReportEvent (string message);

public abstract void ReportEvent (string message, Dictionary<string, object> parameters);

public abstract void ReportError (string condition, string stackTrace);

public abstract void SetTrackLocationEnabled (bool enabled);

public abstract void SetLocation (YandexAppMetricaConfig.Coordinates coordinates);

public abstract void SetSessionTimeout (uint sessionTimeoutSeconds);

public abstract void SetReportCrashesEnabled (bool enabled);

public abstract void SetCustomAppVersion (string appVersion);

public abstract void SetLoggingEnabled ();

public abstract void SetEnvironmentValue (string key, string value);

public abstract bool CollectInstalledApps { get; set; }

public abstract string LibraryVersion { get; }

public abstract int LibraryApiLevel { get; }

}
Loading

0 comments on commit 5d9ebea

Please sign in to comment.