Unity: Singleton DontDestroyOnLoad Build Error
<p>I am using XMGUnityLib Plugin. The program runs fine in the editor without any error but when I try to build it (Android) then while at pushing apk step it gives this error:</p>
<pre><code>InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: AnalyticsManager. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
XMGSingleton`1[XMGAnalyticsManager].get_Instance () (at Assets/XMG/UnityLib/Util/XMGSingleton.cs:28)
AndroidStorePostProcess.OnPostprocessScene () (at Assets/Editor/AndroidStorePostProcess.cs:32)
UnityEditor.HostView:OnGUI()
</code></pre>
<p>XMGSingleton.cs:</p>
<pre><code>using UnityEngine;
using System.Collections;
using System;

/// &lt;summary&gt;
/// XMG singleton base Class.
/// Inherit your Manager Monobehavior classes that you want to be Singletons
/// &lt;/summary&gt;
public abstract class XMGSingleton&lt;T&gt; : MonoBehaviour where T : MonoBehaviour
{
    protected static T instance;
    /// &lt;summary&gt;
    /// Returns the instance of this singleton
    /// Make sure we don't get destroyed on Scene Load
    /// &lt;/summary&gt;
    public static T Instance {
        get {
            
            if(instance == null) {
                instance = (T) FindObjectOfType(typeof(T));
            
                if (instance == null) {
                   Debug.LogError(&quot;An instance of &quot; + typeof(T) + 
                      &quot; is needed in the scene, but there is none.&quot;);
                    return null;
                }

                DontDestroyOnLoad(instance.gameObject);
            }
            return instance;
        }
    }

    #region Public Methods

    public static bool HasInstance {
        get {
            if( (T) FindObjectOfType(typeof(T)) != null ) {
                return true;
            } else {
                return false;
            }
        }
    }
    
    /// &lt;summary&gt;
    /// Helper to cast the Instance to the Type provided
    /// &lt;/summary&gt;
    public static Type MyInstance&lt;Type&gt; () {
        return (Type)(object)Instance;
    }
    
    #endregion
}
</code></pre>
<p>XMGAnalyticsManager.cs:</p>
<pre><code>using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Com.XMG.UnityLib.Community.OnlineGame;
using Com.XMG.UnityLib.Tracking;
    
#if UNITY_IPHONE
    using FlurryAccess = FlurryBinding;
#elif UNITY_ANDROID
    using FlurryAccess = FlurryAndroid;
#endif

public abstract partial class XMGAnalyticsManager : XMGSingleton&lt;XMGAnalyticsManager&gt; {
    
    #region Private Fields
    
    /// &lt;summary&gt;
    /// The type of the current build.
    /// For Analytics QA testing point to Analytics
    /// For QA Testing point to SandBox
    /// For Production/Release build point to Production
    /// &lt;/summary&gt;
    [SerializeField]
    private BuildTypeEnum buildType = BuildTypeEnum.SandBox;
    
    /// &lt;summary&gt;
    /// The type of the android store type
    /// &lt;/summary&gt;
    [SerializeField]
    private AndroidStoreTypeEnum androidStoreType = AndroidStoreTypeEnum.Google;
    
    /// &lt;summary&gt;
    /// The swrve authentication Info
    /// &lt;/summary&gt;
    [SerializeField]
    private SwrveAuthentication swrveAuth;
    
    /// &lt;summary&gt;
    /// The flurry auth.
    /// &lt;/summary&gt;
    [SerializeField]
    private FlurryAuthentication flurryAuth;
    
    /// &lt;summary&gt;
    ///  Sends events every X seconds.
    /// &lt;/summary&gt;
    [SerializeField]
    private float sendEventsEverySeconds = 30;
    
    /// &lt;summary&gt;
    /// The parent screen.
    /// &lt;/summary&gt;
    [SerializeField]
    private string parentScreen = &quot;SplashPage&quot;;
    
    /// &lt;summary&gt;
    /// The grand parent screen.
    /// &lt;/summary&gt;
    string grandParentScreen = &quot;null&quot;;
    
    /// &lt;summary&gt;
    /// My external IP.
    /// &lt;/summary&gt;
    string myExtIP = &quot;&quot;;
    
    /// &lt;summary&gt;
    /// The swrve component.
    /// &lt;/summary&gt;
    private SwrveComponent swrveComponent;
    
    private Dictionary&lt;string, JSONObject&gt; swrveResources = new Dictionary&lt;string, JSONObject&gt;();
    /// &lt;summary&gt;
    /// Resource hashmap ----&gt; (key: resource name, value: json object)
    /// &lt;/summary&gt;
    public Dictionary&lt;string, JSONObject&gt; Resources {
        get {
            return this.swrveResources;
        }
    }
    
    /// &lt;summary&gt;
    /// This event is triggered when swrve data is updated.
    /// &lt;/summary&gt;
    public static event Action ItemsConfigurationUpdatedEvent = delegate {};
    
    /// &lt;summary&gt;
    /// True if we are in the fetching of AB Test Data State
    /// &lt;/summary&gt;
    private bool isFetchingABParams = false;
    
    /// &lt;summary&gt;
    /// The current swrve identifier.
    /// &lt;/summary&gt;
    private string currentSwrveId = null;
    
    /// &lt;summary&gt;
    /// The android bundle version.
    /// &lt;/summary&gt;
    [SerializeField]
    protected string androidBundleVersion = &quot;1.0&quot;;
    
    #endregion
    
    #region Public Properties
    
    /// &lt;summary&gt;
    /// True if it's a production build
    /// &lt;/summary&gt;
    public bool IsProductionBuild {
        get { return buildType == BuildTypeEnum.Production; }
    }
    
    /// &lt;summary&gt;
    /// Gets the type of the android store.
    /// &lt;/summary&gt;
    public AndroidStoreTypeEnum AndroidStoreType {
        get { return androidStoreType; }
        set { androidStoreType = value; }
    }
    
    /// &lt;summary&gt;
    /// True if its a google play store build
    /// &lt;/summary&gt;
    public bool IsGoogleStoreType {
        get { return androidStoreType == AndroidStoreTypeEnum.Google; }
    }
    
    /// &lt;summary&gt;
    /// True if its an Amazon store build
    /// &lt;/summary&gt;
    public bool IsAmazonStoreType {
        get { return androidStoreType == AndroidStoreTypeEnum.Amazon; }
    }
    
    #endregion
    
    #region Monobehaviors &amp; Init
    
    /// &lt;summary&gt;
    /// Add event Listeners
    /// &lt;/summary&gt;
    void Awake() {
        XMGOnlineProfileManager.OnProfileLoadedEvent += ProfileHasLoadedCallback;
        XMGCommunityManager.OnCreateRealProfileOnServerEvent += ProfileCreatedOnServerCallback;
        XMGCommunityManager.OnNewFriendsAddedEvent += NewFriendsAddedCallback;
        
        RegisterGameListeners();
        // TODO: Listen for Profile Change events
        swrveAuth.Init();
        flurryAuth.Init();
    }
    
    /// &lt;summary&gt;
    /// Starts the SWRVE Event timer
    /// &lt;/summary&gt;
    void Start() {
        StartSwrveTimer();
        StartCoroutine( CheckIP() );
    }
    
    /// &lt;summary&gt;
    /// Checks for the IP
    /// &lt;/summary&gt;
    /// &lt;returns&gt;
    /// The IP
    /// &lt;/returns&gt;
    IEnumerator CheckIP(){

        WWW myExtIPWWW = new WWW(&quot;http://checkip.dyndns.org&quot;);
    
        if( myExtIPWWW != null ) {
            yield return myExtIPWWW;
            
            if( myExtIPWWW.error == null ) {
        
                myExtIP=myExtIPWWW.text;
            
                myExtIP=myExtIP.Substring(myExtIP.IndexOf(&quot;:&quot;)+1);
            
                myExtIP=myExtIP.Substring(0,myExtIP.IndexOf(&quot;&lt;&quot;));
            }
        }
    }
    
    
    /// &lt;summary&gt;
    /// Detach event Listeners
    /// &lt;/summary&gt;
    void OnDestroy() {
        XMGOnlineProfileManager.OnProfileLoadedEvent -= ProfileHasLoadedCallback;
        XMGCommunityManager.OnCreateRealProfileOnServerEvent -= ProfileCreatedOnServerCallback;
        XMGCommunityManager.OnNewFriendsAddedEvent -= NewFriendsAddedCallback;
        UnRegisterGameListeners();
    }
    
    /// &lt;summary&gt;
    /// If Pause end session
    /// If Resume Start session and Re-Login.
    /// At any case post events
    /// &lt;/summary&gt;
    /// &lt;param name='pause'&gt;
    /// Pause.
    /// &lt;/param&gt;
    void OnApplicationPause(bool pause) {
        if (currentSwrveId != null) {
            
            if(pause) {
                swrveComponent.Swrve_AddSessionEnd();
            } else {
                swrveComponent.Swrve_AddSessionStart();
                SessionStart();
                AnalyticsLogout();
                AnalyticsLogin();
            }
            
            LogUserProperties();
            swrveComponent.Swrve_PostEvents(currentSwrveId, SWRVE_APP_VERSION);
        }
    }
    
    /// &lt;summary&gt;
    /// Init plugins.The Profile Has loaded
    /// &lt;/summary&gt;
    void ProfileHasLoadedCallback() {
        // Get Swrve component
        swrveComponent = gameObject.GetComponentInChildren&lt;SwrveComponent&gt;();
        AnalyticsLogin();
        
        // Check if we've set the random user property, if not then set it
        if (!PlayerPrefs.HasKey(RANDOM_TEST_PROPERTY_KEY)) {
            PlayerPrefs.SetString(RANDOM_TEST_PROPERTY_KEY, &quot;true&quot;);

            JSONObject userProperty = new JSONObject(JSONObject.Type.OBJECT);
            int random = NGUITools.RandomRange(1, 100);
            userProperty.AddField(&quot;RandNum&quot;, random.ToString());
            
            swrveComponent.Swrve_AddUserUpdateEvent(userProperty.ToString());
        }
        
    }
    
    /// &lt;summary&gt;
    /// A new Online Profile created callback.
    /// &lt;/summary&gt;
    void ProfileCreatedOnServerCallback() {
        AddNamedEvent( &quot;Community.FacebookUserCreated&quot; );
    }
    
    /// &lt;summary&gt;
    /// New friends were added callback.
    /// &lt;/summary&gt;
    /// &lt;param name='newFriendsAdded'&gt;
    /// The New friends added
    /// &lt;/param&gt;
    void NewFriendsAddedCallback( int newFriendsAdded ) {
        JSONObject jTournamentFriends = new JSONObject(JSONObject.Type.OBJECT);
        jTournamentFriends.AddField( &quot;NewFriendsAdded&quot;, BucketGeneral( newFriendsAdded ) );
        AddNamedEvent ( &quot;Community.TournamentAddedFriend&quot;, jTournamentFriends );
    }
    
    #endregion
    
    #region Abstract &amp; Virtual Methods
    
    /// &lt;summary&gt;
    /// Gets the tracking Object
    /// &lt;/summary&gt;
    protected abstract XMGTracking GetTracking();
    
    /// &lt;summary&gt;
    /// Registers the game listeners.
    /// &lt;/summary&gt;
    protected abstract void RegisterGameListeners();
    
    /// &lt;summary&gt;
    /// Unregister the game listeners.
    /// &lt;/summary&gt;
    protected abstract void UnRegisterGameListeners();
    
    /// &lt;summary&gt;
    /// Logs the game user properties.
    /// &lt;/summary&gt;
    /// &lt;param name='jUserProperties'&gt;
    /// The JSON Object with the user properties.
    /// &lt;/param&gt;
    protected abstract void LogGameUserProperties(JSONObject jUserProperties);
    
    /// &lt;summary&gt;
    /// A session Is Started
    /// &lt;/summary&gt;
    protected abstract void SessionStart();
    
    /// &lt;summary&gt;
    /// The session has ended
    /// &lt;/summary&gt;
    protected abstract void SessionEnd();
    
    /// &lt;summary&gt;
    /// Gets the user start time.
    /// Default to Now
    /// Override to provide the user's start time
    /// &lt;/summary&gt;
    /// &lt;returns&gt;
    /// The user start time.
    /// &lt;/returns&gt;
    protected virtual long GetUserStartTime() {
        return (long)XMGUnityUtil.ToUnixTimeFromUniversal( DateTime.UtcNow );
    }
    
    #endregion
    
    #region Private Methods
    
    /// &lt;summary&gt;
    /// Starts the swrve timer.
    /// &lt;/summary&gt;
    private void StartSwrveTimer() {
        StartCoroutine( StartEventsTimer());
    }
    
    /// &lt;summary&gt;
    /// Logs the user properties.
    /// And Calls abstract LogGameUserProperties
    /// &lt;/summary&gt;
    private  void LogUserProperties() {
        JSONObject jUserProperties = new JSONObject(JSONObject.Type.OBJECT);
        // Add here Common User Properties
        XMGTracking tracking = GetTracking();
        
        jUserProperties.AddField( UP_FIRST_LAUNCH_DAY, tracking.FirstLaunch.Day );
        jUserProperties.AddField( UP_FIRST_LAUNCH_MONTH, tracking.FirstLaunch.Month );
        jUserProperties.AddField( UP_FIRST_LAUNCH_YEAR, tracking.FirstLaunch.Year );
        jUserProperties.AddField( UP_FIRST_LAUNCH_EPOCH, XMGUnityUtil.ToUnixTimeFromUniversal( tracking.FirstLaunch ).ToString() );
        jUserProperties.AddField( UP_TOTAL_TAPJOY_REWARDS, tracking.TotalTapJoyPointsEarned );
        jUserProperties.AddField( UP_TOTAL_SPONSORPAY_REWARDS, tracking.TotalSponsorPayPointsEarned );
        jUserProperties.AddField( UP_TOTAL_CHARTBOOST_ADS_CLICKED, tracking.TotalChartBoostAdsClicked );
        jUserProperties.AddField( UP_TOTAL_CHARTBOOST_ADS_CLOSED, tracking.TotalChartBoostAdsClosed );
        
        jUserProperties.AddField( UP_TOTAL_SOFT_CURRENCY_EARNED, tracking.SoftCurrencyEarned );
        jUserProperties.AddField( UP_TOTAL_HARD_CURRENCY_EARNED, tracking.HardCurrencyEarned );
        jUserProperties.AddField( UP_TOTAL_SOFT_CURRENCY_SPENT, tracking.SoftCurrencySpent );
        jUserProperties.AddField( UP_TOTAL_HARD_CURRENCY_SPENT, tracking.HardCurrencySpent );
#if UNITY_IPHONE
        jUserProperties.AddField( UP_VERION, EtceteraTwoBinding.getInfoPlistValue(&quot;CFBundleVersion&quot;) );
#elif UNITY_ANDROID
        jUserProperties.AddField( UP_VERION, androidBundleVersion );
#endif
        jUserProperties.AddField( UP_TOTAL_FRIENDS, tracking.TotalFriends );
        jUserProperties.AddField( UP_TOTAL_UNIQUE_DAYS_PLAYED, tracking.TotalUniqueDaysPlayed );
        if( string.IsNullOrEmpty( myExtIP ) ) {
            jUserProperties.AddField( UP_IP, myExtIP );
        }
        LogGameUserProperties(jUserProperties);
        swrveComponent.Swrve_AddUserUpdateEvent(jUserProperties.ToString());
    }
    
    #endregion
    
    #region Authentication
    
    /// &lt;summary&gt;
    /// Logs in to Flurry and SWRVE
    /// &lt;/summary&gt;
    void AnalyticsLogin() {

        FlurryLogin();
        
        if( currentSwrveId != null ) {
            if( !currentSwrveId.Equals( XMGOnlineProfileManager.Instance.ActiveOnlineProfile.GameStats.SwrveId ) ) {
                Debug.Log(&quot;There is already a swrve account signed in!!! You must close the session first!&quot;);
                AnalyticsLogout();
            } else {
                // This swrve user is already logged in, bail out of this function
                Debug.Log(&quot;Attempt to log into swrve twice with the same id... Ignoring.&quot;);
                return;
            }
        }
        
        SwrveLogin(XMGOnlineProfileManager.Instance.ActiveOnlineProfile.GameStats.SwrveId);
    }
    
    /// &lt;summary&gt;
    /// Logout from Flurry and SWRVE
    /// &lt;/summary&gt;
    private void AnalyticsLogout() {
        
        FlurryLogout();
        
        if(currentSwrveId == null) {
            Debug.LogError(&quot;There is no active swrve user!!! Cannot close session.&quot;);
            return;
        }
        
        SwrveLogout();
    }
    
    
    /// &lt;summary&gt;
    /// Starts Flurry Session
    /// &lt;/summary&gt;
    private void FlurryLogin() {
#if UNITY_IPHONE
        FlurryAccess.startSession(flurryAuth.FlurryKey);
#elif UNITY_ANDROID
        FlurryAccess.onStartSession(flurryAuth.FlurryKey, true, true );
#endif
    }
    
    /// &lt;summary&gt;
    /// Logouts from Flurry
    /// &lt;/summary&gt;
    private void FlurryLogout() {
#if UNITY_ANDROID
        FlurryAccess.onEndSession();
#endif
    }
    
    /// &lt;summary&gt;
    /// Login to Swrve
    /// &lt;/summary&gt;
    /// &lt;param name='swrveId'&gt;
    /// The Swrve identifier.
    /// &lt;/param&gt;
    private void SwrveLogin(string swrveId) {
        
        currentSwrveId = swrveId;
        
        int gameId = 0;
        string apiKey = &quot;&quot;;
        
        if (buildType == BuildTypeEnum.Analytics) {
            gameId = swrveAuth.AnalyticsGameID;
            apiKey = swrveAuth.AnalyticsAPIKey;
        } else if (buildType == BuildTypeEnum.SandBox) {
            gameId = swrveAuth.SandboxGameID;
            apiKey = swrveAuth.SandboxAPIKey;
        } else if( buildType == BuildTypeEnum.Production ) {
            gameId = swrveAuth.ProductionGameID;
            apiKey = swrveAuth.ProductionAPIKey;
        }
        
        
        InitializeSWRVEComponent(gameId,
                    apiKey,
                    swrveAuth.PersonalKey,
                    swrveAuth.URLABTest
                    );
    }
    
    /// &lt;summary&gt;
    /// Logout from Swrve
    /// &lt;/summary&gt;
    private void SwrveLogout() {
        // Make sure to close the Swrve session
        SessionEnd();
        swrveComponent.Swrve_AddSessionEnd();
        swrveComponent.Swrve_PostEvents(currentSwrveId, SWRVE_APP_VERSION);
        currentSwrveId = null;
    }
    
    /// &lt;summary&gt;
    /// Initializes the SWRVE component.
    /// &lt;/summary&gt;
    /// &lt;param name='gameId'&gt;
    /// The Game identifier.
    /// &lt;/param&gt;
    /// &lt;param name='apiKey'&gt;
    /// The API key.
    /// &lt;/param&gt;
    /// &lt;param name='personalKey'&gt;
    /// Personal key.
    /// &lt;/param&gt;
    /// &lt;param name='abURL'&gt;
    /// The Ab Test server URL.
    /// &lt;/param&gt;
    private void InitializeSWRVEComponent(int gameId, string apiKey, string personalKey, string abURL) {
        swrveComponent.gameId = gameId;
        swrveComponent.apiKey = apiKey;
        swrveComponent.abTestServer = abURL;
        
        // Setup swrve for new user
        swrveComponent.Swrve_AddSessionStart();
        SessionStart();
        if(isFetchingABParams == false) {
            isFetchingABParams = true;
            StartCoroutine(GetAllResourcesWithABTests());
        }
    }
    
    #endregion
    
    #region A/B Helpers
    
    /// &lt;summary&gt;
    /// Returns the most recent JSON configuration for a resource from swrve or NULL if there is none.
    /// This means it could return cached data that is old. If you want to retrieve the latest from swrve.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;itemId&quot;&gt;
    /// A &lt;see cref=&quot;System.String&quot;/&gt;
    /// &lt;/param&gt;
    /// &lt;returns&gt;
    /// A &lt;see cref=&quot;JSONObject&quot;/&gt;
    /// &lt;/returns&gt;
    public JSONObject GetItemParams(string itemId) {
        JSONObject item = null;
        swrveResources.TryGetValue(itemId, out item);
        return item;
    }
    
    /// &lt;summary&gt;
    /// Gets all resources with AB tests.
    /// &lt;/summary&gt;
    /// &lt;returns&gt;
    /// The all resources with AB tests.
    /// &lt;/returns&gt;
    private IEnumerator GetAllResourcesWithABTests() {
        
        string swrveURLRequest = string.Format(swrveAuth.URLABTestResources + &quot;?api_key={0}&amp;user={1}&amp;joined={2}&quot;, swrveComponent.apiKey, currentSwrveId, GetUserStartTime() );
        WWW itemRequest = new WWW(swrveURLRequest);
        yield return itemRequest; // Yield until a result is returned.
        
        if(itemRequest.error != null) {
            Debug.LogWarning(&quot;Error attempting to fetch Swrve A/B Resource data: &quot; + itemRequest.error);
            LoadCachedConfig();
            // Bail!
            yield break;
        }
        
        // Process all the resources into a hashmap ( key: resource name,  value: json object )
        JSONObject jResources = new JSONObject(itemRequest.text);
        if(jResources == null || jResources.type == JSONObject.Type.NULL) {
            // Bad data from swrve, abort!
            Debug.LogError(&quot;Bad A/B resource data from swrve!&quot;);
            LoadCachedConfig();
            yield break;
        } else {
            //Debug.LogWarning( &quot;Data from SWRVE: &quot; + jResources );
        }
        
        XMGSaveLoadUtils.Instance.SaveEncryptedField(CACHED_CONFIG_KEY, itemRequest.text); // Replace the old cached config.
        ParseResources(jResources);
        if( swrveResources.Count &gt; 0 ) {
            ItemsConfigurationUpdatedEvent();
        }
        
        isFetchingABParams = false;
    }
    
    /// &lt;summary&gt;
    /// Loads the cached swrve config file
    /// &lt;/summary&gt;
    private void LoadCachedConfig() {
        string cached = XMGSaveLoadUtils.Instance.LoadEncryptedField(CACHED_CONFIG_KEY);
        
        if(string.IsNullOrEmpty(cached)) {
            // There was no cached data
            return;
        }
        
        // Apply the cached resources so it doesn't block updates.
        JSONObject jResources = new JSONObject(cached);
        ParseResources(jResources);
        if( swrveResources.Count &gt; 0 ) {
            ItemsConfigurationUpdatedEvent();
        }
    }
    
    /// &lt;summary&gt;
    ///  Expects a JSON array of resources.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;resources&quot;&gt;
    /// A &lt;see cref=&quot;JSONObject&quot;/&gt;
    /// &lt;/param&gt;
    private void ParseResources(JSONObject jResources) {
        swrveResources.Clear();
        //Debug.Log( &quot;Parsing SWRVE Resources: &quot; + jResources );
        
        if(jResources == null || jResources.type != JSONObject.Type.ARRAY) {
            // Bad data from swrve, abort!
            Debug.LogError(&quot;Could not parse resource data, unexpected format!&quot;);
            return;
        }
        
        foreach(JSONObject data in jResources.list) {
            JSONObject key = data.GetField(&quot;uid&quot;);
            if(key == null || key.type != JSONObject.Type.STRING || string.IsNullOrEmpty( JSONObject.GetString(key) ) ) {
                // Bad item, on to the next
                Debug.LogWarning(&quot;Bad item, no property 'uid' in &quot; + data.print());
                continue;
            }
            // Add the resource over top of any precached configuration
            swrveResources[JSONObject.GetString(key)] = data;
        }
    }
    
    #endregion
    
    #region Event Handling
    
    /// &lt;summary&gt;
    /// Adds the named event.
    /// &lt;/summary&gt;
    /// &lt;param name='name'&gt;
    /// The EventName.
    /// &lt;/param&gt;
    public void AddNamedEvent(string name) {
        swrveComponent.Swrve_AddNamedEvent(name, &quot;{}&quot;);
#if UNITY_IPHONE
        FlurryAccess.logEvent(name, false);
#elif UNITY_ANDROID
        FlurryAccess.logEvent(name);
#endif
    }
    
    /// &lt;summary&gt;
    /// Adds a named event with Payload
    /// &lt;/summary&gt;
    /// &lt;param name='name'&gt;
    /// The EventName.
    /// &lt;/param&gt;
    /// &lt;param name='payload'&gt;
    /// Payload.
    /// &lt;/param&gt;
    public void AddNamedEvent(string name, JSONObject payload) {
        string data = payload.ToString();
        
        if(!string.IsNullOrEmpty(data)) {
            swrveComponent.Swrve_AddNamedEvent(name, data);
        } else {
            swrveComponent.Swrve_AddNamedEvent(name, &quot;{}&quot;);
        }
        
#if UNITY_IPHONE
        FlurryAccess.logEventWithParameters(name, payload.ToDictionary(), false);
#elif UNITY_ANDROID
        FlurryAccess.logEvent(name, payload.ToDictionary());
#endif
    }
    
    /// &lt;summary&gt;
    /// Infinite Loop to send events in the queue
    /// &lt;/summary&gt;
    private IEnumerator StartEventsTimer() {
        float timeInterval = Time.realtimeSinceStartup;
        while (true) {
            if(Time.realtimeSinceStartup - timeInterval &gt;= sendEventsEverySeconds) {
                SendEvents();
                timeInterval = Time.realtimeSinceStartup;
            }
            yield return new WaitForSeconds( 1 );
        }
    }
    
    /// &lt;summary&gt;
    /// Sends the events to SWRVE
    /// &lt;/summary&gt;
    private void SendEvents() {
        if(currentSwrveId != null) {
            swrveComponent.Swrve_PostEvents(currentSwrveId, SWRVE_APP_VERSION);
        }
    }
    
    #endregion
    
    #region UI Events
    
    /// &lt;summary&gt;
    /// Logs a UI screen visit event.
    /// Records the current screen, the parent screen, and the grandparent screen.
    /// &lt;/summary&gt;
    /// &lt;param name='screenName'&gt;
    /// Screen name.
    /// &lt;/param&gt;
    public void ScreenVisitEvent(string screenName) {
        
        JSONObject eventParams = new JSONObject(JSONObject.Type.OBJECT);
        
        if(parentScreen != null) {
            eventParams.AddField(&quot;parent&quot;, parentScreen);
        }
        if(grandParentScreen != null) {
            eventParams.AddField(&quot;grandParent&quot;, grandParentScreen);
        }
        
        AddNamedEvent(&quot;UI.Flow.&quot; + screenName, eventParams);
        
        eventParams.AddField(&quot;screen&quot;, screenName);
        AddNamedEvent(&quot;UI.Flow.Screens&quot;, eventParams);
        
        grandParentScreen = parentScreen;
        parentScreen = screenName;
    }
    
    /// &lt;summary&gt;
    /// Logs a UI button pressed event
    /// &lt;/summary&gt;
    /// &lt;param name='buttonName'&gt;
    /// The Button name.
    /// &lt;/param&gt;
    public void ButtonPressedEvent( string buttonName ) {
        AddNamedEvent(&quot;UI.ButtonPressed.&quot; + buttonName );
    }
    
    #endregion
    
    #region Purchase Events
    
    /// &lt;summary&gt;
    /// Sends an analytics buy in event for purchasing inapps.
    /// &lt;/summary&gt;
    /// &lt;param name='rewardCurrency'&gt;
    /// Reward currency
    /// &lt;/param&gt;
    /// &lt;param name='rewardAmount'&gt;
    ///  Amount of rewardCurrency
    /// &lt;/param&gt;
    /// &lt;param name='localCost'&gt;
    /// The real money price in local currency ( e.g 0.99 )
    /// &lt;/param&gt;
    /// &lt;param name='localCurrency'&gt;
    /// CAD, USD, etc...
    /// &lt;/param&gt;
    public void AddBuyInEvent(string rewardCurrency, int rewardAmount, float localCost, string localCurrency, string itemID ) {
        swrveComponent.Swrve_AddBuyInEvent( &quot;&quot;, rewardCurrency, rewardAmount, Mathf.Round(localCost* 100)/100, localCurrency );
        AddNamedEvent( &quot;Purhases.IAP&quot; );
        AddNamedEvent( &quot;Purhases.IAP.HardCurrency&quot; + itemID );
    }
    
    /// &lt;summary&gt;
    /// Analytics event when a user purchases an item in-game.
    /// &lt;/summary&gt;
    /// &lt;param name='itemID'&gt;
    /// The UID for the Item
    /// &lt;/param&gt;
    /// &lt;param name='currency'&gt;
    /// The currency
    /// &lt;/param&gt;
    /// &lt;param name='itemCost'&gt;
    /// Item cost.
    /// &lt;/param&gt;
    /// &lt;param name='itemQuantity'&gt;
    /// Item quantity.
    /// &lt;/param&gt;
    public void AddPurchaseEvent( string itemID, string currency, int itemCost, int itemQuantity ) {
        swrveComponent.Swrve_AddPurchaseItemEvent( itemID, currency, itemCost, itemQuantity );
    }
    
    /// &lt;summary&gt;
    /// Adds a purchase conversion event.
    /// &lt;/summary&gt;
    /// &lt;param name='itemID'&gt;
    ///The unique Item ID
    /// &lt;/param&gt;
    public void AddPurchaseConversionPackEvent( string itemID ) {
        AddNamedEvent( &quot;Purchases.HardCurrency.SoftCurrency&quot; );
        AddNamedEvent( &quot;Purhases.HardCurrency.SoftCurrency.&quot; + itemID );
    }
    
    #endregion
}
</code></pre>
<p>Is this singleton class correctly coded? If yes, what could be the problem?
Any help will be appreciated.
Thanks :)</p>