Class AnalyticsService
This service provides support for sending analytics events to one or more endpoints. The application will log an IAnalyticsEvent through this API and the event will be passed to the IAnalyticsDispatcher objects that have been added through the configuration. Exceptions and session related events will also be caught and logged automatically.
Namespace: IdleKit.Analytics
Assembly: cs.temp.dll.dll
Syntax
public class AnalyticsService : ServiceBase, IAnalyticsService, IService
Fields
_actionService
Declaration
protected IActionService _actionService
Field Value
Type | Description |
---|---|
IActionService |
_analyticsEnvironmentConfig
Declaration
protected IAnalyticsEnvironmentConfig _analyticsEnvironmentConfig
Field Value
Type | Description |
---|---|
IAnalyticsEnvironmentConfig |
_dataService
Declaration
protected IDataService _dataService
Field Value
Type | Description |
---|---|
IDataService |
_dataStoreService
Declaration
protected IDataStoreService _dataStoreService
Field Value
Type | Description |
---|---|
IDataStoreService |
_dispatchers
Declaration
protected List<IAnalyticsDispatcher> _dispatchers
Field Value
Type | Description |
---|---|
List<IAnalyticsDispatcher> |
_resolver
Declaration
protected IResolver _resolver
Field Value
Type | Description |
---|---|
IResolver |
_userSavedData
Declaration
protected IUserSavedData _userSavedData
Field Value
Type | Description |
---|---|
IUserSavedData |
Methods
CleanStackTrace(String)
Cleans the stack trace passed to Kraang. Removes log and unity functions from stack to reduce size. Will leave line numbers if in UnityEditor.
Declaration
protected string CleanStackTrace(string stackTrace)
Parameters
Type | Name | Description |
---|---|---|
String | stackTrace | stack string passed from unity |
Returns
Type | Description |
---|---|
String | cleaned stack string |
CleanupService()
Declaration
protected override void CleanupService()
HandleApplicationPaused(Boolean)
Send Analytics events when the game is sent to the background and resumed. These events track the session duration internally so the app does not need to worry about that.
Declaration
protected virtual void HandleApplicationPaused(bool pauseStatus)
Parameters
Type | Name | Description |
---|---|---|
Boolean | pauseStatus |
HandleExceptionHandled(Exception)
Catches and logs exceptions.>. Exceptions are filtered based on the IAnalyticsEnvironmentConfig so each IEnvironmentConfig can log a different set of exceptions.
Declaration
protected virtual void HandleExceptionHandled(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception |
HandleIdleKitInitialized(IdleKitInitializedAction)
Declaration
protected void HandleIdleKitInitialized(IdleKitInitializedAction action)
Parameters
Type | Name | Description |
---|---|---|
IdleKitInitializedAction | action |
HandleLogMessageReceived(String, String, LogType)
Catches and logs all errors and exceptions.>.
Declaration
protected virtual void HandleLogMessageReceived(string logmessage, string stacktrace, LogType type)
Parameters
Type | Name | Description |
---|---|---|
String | logmessage | |
String | stacktrace | |
LogType | type |
Initialize()
Declaration
public override void Initialize()
InitializeService()
Declaration
protected override void InitializeService()
Inject(IResolver)
Declaration
public override void Inject(IResolver resolver)
Parameters
Type | Name | Description |
---|---|---|
IResolver | resolver |
LoadEnvironmentConfig()
Declaration
protected virtual void LoadEnvironmentConfig()
LogEvent(IAnalyticsEvent)
Log a single IAnalyticsEvent.
Declaration
public virtual void LogEvent(IAnalyticsEvent analyticsEvent)
Parameters
Type | Name | Description |
---|---|---|
IAnalyticsEvent | analyticsEvent | The event to log. This event should already be initialized and ready to log. |
LogEvent(Type, Action<IAnalyticsEvent>)
Use this method if the event you are logging needs to resolve dependencies before being initialized. Creating a new instance of an event and logging it will not result in dependencies being injected.
Declaration
public void LogEvent(Type eventType, Action<IAnalyticsEvent> initializeEventMethod)
Parameters
Type | Name | Description |
---|---|---|
Type | eventType | The type of event to log. |
Action<IAnalyticsEvent> | initializeEventMethod | The callback that will allow for event initialization. |
LogEvent<TEvent>(Action<TEvent>)
Use this method if the event you are logging needs to resolve dependencies before being initialized. Creating a new instance of an event and logging it will not result in dependencies being injected.
Declaration
public virtual void LogEvent<TEvent>(Action<TEvent> initializeEventMethod)
where TEvent : IAnalyticsEvent
Parameters
Type | Name | Description |
---|---|---|
Action<TEvent> | initializeEventMethod |
Type Parameters
Name | Description |
---|---|
TEvent |
LogEvents(IEnumerable<IAnalyticsEvent>)
Log multiple IAnalyticsEvents. Useful for implementations that can handle batching events together.
Declaration
public virtual void LogEvents(IEnumerable<IAnalyticsEvent> analyticsEvents)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IAnalyticsEvent> | analyticsEvents | The events to log. These events should already be initialized and ready to log. |
LogEventsInternal(IAnalyticsEvent[])
The central log events method. All event logging goes through here.
Declaration
protected virtual void LogEventsInternal(params IAnalyticsEvent[] analyticsEvents)
Parameters
Type | Name | Description |
---|---|---|
IAnalyticsEvent[] | analyticsEvents | The events to log. |
SendPendingEvents()
Get all IAnalyticsDispatchers to output any cached IAnalyticsEvents immediately.
Declaration
public void SendPendingEvents()
StripHTML(String)
Strings any html tags from strings
Declaration
protected string StripHTML(string input)
Parameters
Type | Name | Description |
---|---|---|
String | input | input string |
Returns
Type | Description |
---|---|
String | cleaned string |
UpdatePendingEvents(Action<IEnumerable<IAnalyticsEvent>>)
Run a method on any cached IAnalyticsEvents in the IAnalyticsDispatchers before they are output.
Declaration
public virtual void UpdatePendingEvents(Action<IEnumerable<IAnalyticsEvent>> updateMethod)
Parameters
Type | Name | Description |
---|---|---|
Action<IEnumerable<IAnalyticsEvent>> | updateMethod | The method to run on cached events before they are sent. |