Пример #1
0
        public void TestManagerMultipleInstance()
        {
            string appID1 = Guid.NewGuid().ToString();
            string appID2 = Guid.NewGuid().ToString();
            string appID3 = Guid.NewGuid().ToString();

            MobileAnalyticsManager manager1 = MobileAnalyticsManager.GetOrCreateInstance(appID1, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());
            MobileAnalyticsManager manager2 = MobileAnalyticsManager.GetOrCreateInstance(appID2, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());
            MobileAnalyticsManager manager3 = MobileAnalyticsManager.GetOrCreateInstance(appID3, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());

            var    type1                = manager1.GetType();
            var    property1            = type1.GetProperty("ClientContext", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var    clientContext1       = property1.GetValue(manager1, null) as ClientContext;
            string clientContextString1 = clientContext1.ToJsonString();

            var    type2                = manager2.GetType();
            var    property2            = type2.GetProperty("ClientContext", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var    clientContext2       = property2.GetValue(manager2, null) as ClientContext;
            string clientContextString2 = clientContext2.ToJsonString();

            var    type3                = manager3.GetType();
            var    property3            = type3.GetProperty("ClientContext", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var    clientContext3       = property3.GetValue(manager3, null) as ClientContext;
            string clientContextString3 = clientContext3.ToJsonString();

            Assert.IsTrue(clientContextString1.IndexOf(appID1) > 0);
            Assert.IsTrue(clientContextString2.IndexOf(appID2) > 0);
            Assert.IsTrue(clientContextString3.IndexOf(appID3) > 0);
        }
Пример #2
0
        public void TestManagerAddClientContextCustomAttribute()
        {
            string KEY1   = Guid.NewGuid().ToString();
            string KEY2   = Guid.NewGuid().ToString();
            string VALUE1 = Guid.NewGuid().ToString();
            string VALUE2 = Guid.NewGuid().ToString();
            string appID  = Guid.NewGuid().ToString();

            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());

            manager.AddCustomAttributeToClientContext(KEY1, VALUE1);
            manager.AddCustomAttributeToClientContext(KEY2, VALUE2);

            var    type                = manager.GetType();
            var    property            = type.GetProperty("ClientContext", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var    clientContext       = property.GetValue(manager, null) as ClientContext;
            string clientContextString = clientContext.ToJsonString();

            Assert.IsTrue(clientContextString.IndexOf("custom") > 0);
            Assert.IsTrue(clientContextString.IndexOf(KEY1) > 0);
            Assert.IsTrue(clientContextString.IndexOf(KEY2) > 0);
            Assert.IsTrue(clientContextString.IndexOf(VALUE1) > 0);
            Assert.IsTrue(clientContextString.IndexOf(VALUE2) > 0);

            Assert.IsTrue(clientContextString.IndexOf("custom") < clientContextString.IndexOf(KEY1));
            Assert.IsTrue(clientContextString.IndexOf("custom") < clientContextString.IndexOf(KEY2));
            Assert.IsTrue(clientContextString.IndexOf(KEY1) < clientContextString.IndexOf(VALUE1));
            Assert.IsTrue(clientContextString.IndexOf(KEY2) < clientContextString.IndexOf(VALUE2));
        }
        public void TestConstructor()
        {
            string appID1 = Guid.NewGuid().ToString();

            MobileAnalyticsManager.GetOrCreateInstance(appID1, TestRunner.Credentials, RegionEndpoint.USEast1);
            MobileAnalyticsManager mam = MobileAnalyticsManager.GetInstance(appID1);

            Assert.IsNotNull(mam);

            string appID2 = Guid.NewGuid().ToString();

            MobileAnalyticsManager.GetOrCreateInstance(appID2, TestRunner.Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());
            Assert.IsNotNull(MobileAnalyticsManager.GetInstance(appID2));

            string notInstantiatedID = Guid.NewGuid().ToString();

            try
            {
                MobileAnalyticsManager.GetInstance(notInstantiatedID);
                Assert.Fail();
            }
            catch (InvalidOperationException e)
            {
                Utils.AssertTrue(e is InvalidOperationException);
            }
        }
        //[Test]
        // [Category("WWW")]
        public void TestErrorEventHandler()
        {
            string appID                   = Guid.NewGuid().ToString();
            bool   gotException            = false;
            int    timeout                 = 2;
            var    ars                     = new AutoResetEvent(false);
            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID,
                                                                                        new CognitoAWSCredentials("wrong-cognito-pool-id", RegionEndpoint.USEast1),
                                                                                        RegionEndpoint.USEast1);

            manager.MobileAnalyticsErrorEvent += (object sender, MobileAnalyticsErrorEventArgs args) =>
            {
                gotException = true;
                ars.Set();
            };


            while (!gotException && timeout > 0)
            {
                ars.WaitOne(TimeSpan.FromSeconds(75));
                timeout--;
            }

            Utils.AssertTrue(gotException);
        }
Пример #5
0
        public void TestSessionTimeout()
        {
            MobileAnalyticsManagerConfig maConfig = new MobileAnalyticsManagerConfig();

            Console.WriteLine("session delta is " + maConfig.SessionTimeout);

            string appID = Guid.NewGuid().ToString();

            // create AmazonMobileAnayticsManager instance
            MobileAnalyticsManager.GetOrCreateInstance(appID, Credentials, RegionEndpoint.USEast1, maConfig);
            Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session = new Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session(appID, new MobileAnalyticsManagerConfig());
            session.Start();
            DateTime startTime1 = session.StartTime;
            string   sessionId1 = session.SessionId;

            // sleep for a while but wake up before session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout - 1) * 1000));
            session.Resume();

            // make sure session is not expired
            DateTime startTime2 = session.StartTime;
            string   sessionId2 = session.SessionId;

            Assert.IsTrue(startTime1 == startTime2 && sessionId1 == sessionId2);

            // sleep longer until session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout + 1) * 1000));
            session.Resume();

            // make sure session is expired
            DateTime startTime3 = session.StartTime;
            string   sessionId3 = session.SessionId;

            Assert.IsTrue(startTime3 > startTime2 && sessionId2 != sessionId3);

            // sleep for a while but wake up before session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout - 1) * 1000));
            session.Resume();

            // make sure session is not expired
            DateTime startTime4 = session.StartTime;
            string   sessionId4 = session.SessionId;

            Assert.IsTrue(startTime4 == startTime3 && sessionId4 == sessionId3);

            // sleep longer until session expires
            session.Pause();
            Thread.Sleep(Convert.ToInt32((maConfig.SessionTimeout + 1) * 1000));
            session.Resume();

            // make sure session is expired
            DateTime startTime5 = session.StartTime;
            string   sessionId5 = session.SessionId;

            Assert.IsTrue(startTime5 > startTime4 && sessionId5 != sessionId4);
        }
        // Use this for initialization
        void Start()
        {
            UnityInitializer.AttachToGameObject(this.gameObject);

            _credentials     = new CognitoAWSCredentials(IdentityPoolId, _CognitoIdentityRegion);
            analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(appId, _credentials,
                                                                          _AnalyticsRegion);
        }
        public void Start()
        {
            if (m_cognitoIdentity == null || string.IsNullOrEmpty(m_analyticsAppId))
            {
                Debug.LogWarning("MobileAnalytics: Analytics manager is not initialized");
                return;
            }

            m_analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(m_analyticsAppId,
                                                                            m_cognitoIdentity.Credentials,
                                                                            AWSRegionHelpers.GetByEnum(m_region));
        }
        public void TestRecordEvent()
        {
            string appID = TestRunner.StoredSettings.AppId;
            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1);

            // sleep a while to make sure event is stored before we delete all event record before now
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();
            SQLiteEventStore eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());
            // remove all rows submitted before
            var allEventList       = eventStore.GetEvents(appID, 10000);
            var deleteEventsIdList = new List <string>();

            foreach (JsonData eventData in allEventList)
            {
                deleteEventsIdList.Add(eventData["id"].ToString());
            }
            eventStore.DeleteEvent(deleteEventsIdList);
            Assert.AreEqual(0, eventStore.NumberOfEvents(appID));


            try
            {
                CustomEvent customEvent = new CustomEvent("TestRecordEvent");
                customEvent.AddAttribute("LevelName", "Level5");
                customEvent.AddAttribute("Successful", "True");
                customEvent.AddMetric("Score", 12345);
                customEvent.AddMetric("TimeInLevel", 64);
                manager.RecordEvent(customEvent);

                MonetizationEvent monetizationEvent = new MonetizationEvent();
                monetizationEvent.Quantity           = 10.0;
                monetizationEvent.ItemPrice          = 2.00;
                monetizationEvent.ProductId          = "ProductId123";
                monetizationEvent.ItemPriceFormatted = "$2.00";
                monetizationEvent.Store         = "Amazon";
                monetizationEvent.TransactionId = "TransactionId123";
                monetizationEvent.Currency      = "USD";
                manager.RecordEvent(monetizationEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine("Catch exception: " + e.ToString());
                Assert.Fail();
            }

            // sleep a while to make sure event is stored
            Task.Delay(TimeSpan.FromSeconds(10)).Wait();

            // Event store should have one custom event, one monetization event
            long num = eventStore.NumberOfEvents(appID);

            Assert.AreEqual(2, eventStore.NumberOfEvents(appID));
        }
        public void TestRecordEvent()
        {
            // Need to make sure that background runner does not attempt to deliver events during
            // test (and consequently delete them from local storage). Restart Background runner
            // and sleep until after it checks for events to send.
            BackgroundRunner.AbortBackgroundThread();
            System.Reflection.FieldInfo fieldInfo        = typeof(MobileAnalyticsManager).GetField("_backgroundRunner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            BackgroundRunner            backgroundRunner = fieldInfo.GetValue(null) as BackgroundRunner;

            backgroundRunner.StartWork();
            Thread.Sleep(1000);

            string appID = Guid.NewGuid().ToString();
            MobileAnalyticsManager manager    = MobileAnalyticsManager.GetOrCreateInstance(appID, TestRunner.Credentials, RegionEndpoint.USEast1);
            SQLiteEventStore       eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());

            try
            {
                CustomEvent customEvent = new CustomEvent("TestRecordEvent");
                customEvent.AddAttribute("LevelName", "Level5");
                customEvent.AddAttribute("Successful", "True");
                customEvent.AddMetric("Score", 12345);
                customEvent.AddMetric("TimeInLevel", 64);
                manager.RecordEvent(customEvent);

                MonetizationEvent monetizationEvent = new MonetizationEvent();
                monetizationEvent.Quantity           = 10.0;
                monetizationEvent.ItemPrice          = 2.00;
                monetizationEvent.ProductId          = "ProductId123";
                monetizationEvent.ItemPriceFormatted = "$2.00";
                monetizationEvent.Store         = "Amazon";
                monetizationEvent.TransactionId = "TransactionId123";
                monetizationEvent.Currency      = "USD";
                manager.RecordEvent(monetizationEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine("Catch exception: " + e.ToString());
                Assert.Fail();
            }

            // sleep a while to make sure event is stored
            Thread.Sleep(TimeSpan.FromSeconds(1));

            // Event store should have one custom event, one monetization event and one session start event.
            Assert.AreEqual(3, eventStore.NumberOfEvents(appID));


            eventStore.Dispose();
        }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        UnityInitializer.AttachToGameObject(this.gameObject);

        //AWS Mobile Analytics init
        analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(mobileAppId, new CognitoAWSCredentials(mobileIdentityPoolId, _Region), AnalyticsRegion);

        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

        // Open your datasets
        userInfo = SyncManager.OpenOrCreateDataset("UserInfo");

        userInfo.OnSyncSuccess += SyncSuccessCallback;
        userInfo.OnSyncFailure += SynFailure;

        // init user Info
        loginTime = DateTime.Now.ToString();
        float randomNum = UnityEngine.Random.Range(0f, 10.0f);

        userId = getLoginId((int)randomNum);

        userInfo.Put("userId", userId);
        userInfo.Put("loginTime", loginTime);

        Debug.Log("userId::::" + userId);
        Debug.Log("loginTime::::" + loginTime);

        userInfo.SynchronizeAsync();

        CustomEvent customEvent = new CustomEvent("SceneLoading");

        // Add attributes
        customEvent.AddAttribute("SceneName", "scene3");
        customEvent.AddAttribute("UserId", "user0000");
        customEvent.AddAttribute("Successful", "True");

        // Add metrics
        customEvent.AddMetric("Score", (int)UnityEngine.Random.Range(0f, 10000.0f));
        customEvent.AddMetric("TimeInLevel", (int)UnityEngine.Random.Range(0f, 500.0f));

        // Record the event
        analyticsManager.RecordEvent(customEvent);

        Debug.Log("SynchronizeAsync Called::::");

        Button btn = btnGoToScene4.GetComponent <Button>();

        btn.onClick.AddListener(TaskOnClick);
    }
Пример #11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button customEventButton       = FindViewById <Button>(Resource.Id.button_custom_event);
            Button monetizationEventButton = FindViewById <Button>(Resource.Id.button_monetization_event);


            customEventButton.Click += delegate
            {
                CustomEvent customEvent = new CustomEvent("level_complete");

                customEvent.AddAttribute("LevelName", "Level5");
                customEvent.AddAttribute("Successful", "True");
                customEvent.AddMetric("Score", 12345);
                customEvent.AddMetric("TimeInLevel", 64);

                _manager.RecordEvent(customEvent);
            };


            monetizationEventButton.Click += delegate
            {
                MonetizationEvent monetizationEvent = new MonetizationEvent();

                monetizationEvent.Quantity           = 10.0;
                monetizationEvent.ItemPrice          = 2.00;
                monetizationEvent.ProductId          = "ProductId123";
                monetizationEvent.ItemPriceFormatted = "$2.00";
                monetizationEvent.Store         = "Amazon";
                monetizationEvent.TransactionId = "TransactionId123";
                monetizationEvent.Currency      = "USD";

                _manager.RecordEvent(monetizationEvent);
            };


            // customize your Mobile Analytics Manager Config
            MobileAnalyticsManagerConfig config = new MobileAnalyticsManagerConfig();

            config.AllowUseDataNetwork = true;

            _manager = MobileAnalyticsManager.GetOrCreateInstance(APP_ID, new CognitoAWSCredentials(COGNITO_POOL_ID, COGNITO_REGION), RegionEndpoint.USEast1, config);
        }
Пример #12
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method


            // customize your Mobile Analytics Manager Config
            MobileAnalyticsManagerConfig config = new MobileAnalyticsManagerConfig();

            config.AllowUseDataNetwork = true;

            ViewController.Manager = MobileAnalyticsManager.GetOrCreateInstance(APP_ID, new CognitoAWSCredentials(COGNITO_POOL_ID, COGNITO_REGION), RegionEndpoint.USEast1, config);

            return(true);
        }
Пример #13
0
        public void Init()
        {
            var config = new MobileAnalyticsManagerConfig();

            config.AllowUseDataNetwork = true;                                                      // Override the default Mobile Analytics Manager configuration if you need.

            _manager = MobileAnalyticsManager.GetOrCreateInstance(_amazonMobileAnalyticsAppId,      //Amazon Mobile Analytics App ID
                                                                  new CognitoAWSCredentials(
                                                                      _amazonCognitoIdentityPoolId, //Amazon Cognito Identity Pool ID
                                                                      RegionEndpoint.USEast1),
                                                                  RegionEndpoint.USEast1,
                                                                  config);

            _manager.ResumeSession();

            Enabled = true;
        }
Пример #14
0
        public void TestErrorEventHandler()
        {
            string appID = Guid.NewGuid().ToString();
            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, new CognitoAWSCredentials("wrong-cognito-pool-id", RegionEndpoint.USEast1), RegionEndpoint.USEast1);

            manager.MobileAnalyticsErrorEvent += errorHandler;

            Task.Delay(TimeSpan.FromSeconds(75)).Wait();
            lock (_lock)
            {
                Assert.IsTrue(resultList.Count > 0);
                foreach (bool result in resultList)
                {
                    Assert.IsTrue(result);
                }
            }
        }
Пример #15
0
        // Use this for initialization
        void Start()
        {
#if UNITY_EDITOR
            /// This is just to spoof the application to think that its running on iOS platform
            AmazonHookedPlatformInfo.Instance.Platform        = "iPhoneOS";
            AmazonHookedPlatformInfo.Instance.Model           = "iPhone";
            AmazonHookedPlatformInfo.Instance.Make            = "Apple";
            AmazonHookedPlatformInfo.Instance.Locale          = "en_US";
            AmazonHookedPlatformInfo.Instance.PlatformVersion = "8.1.2";

            AmazonHookedPlatformInfo.Instance.Title       = "YourApp";
            AmazonHookedPlatformInfo.Instance.VersionName = "v1.0";
            AmazonHookedPlatformInfo.Instance.VersionCode = "1.0";
            AmazonHookedPlatformInfo.Instance.PackageName = "com.yourcompany.yourapp";
#endif
            _credentials     = new CognitoAWSCredentials(IdentityPoolId, Amazon.RegionEndpoint.USEast1);
            analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(_credentials,
                                                                          Amazon.RegionEndpoint.USEast1, appId);
        }
Пример #16
0
        public static bool init()
        {
            bool ret = ReadCofig();

            if (ret == false)
            {
                Logger.LogMessage(typeof(Program), Logger.Severity.Error,
                                  "Failed to read config file " + ConfigXmlFile);
                return(false);
            }

            Amazon.AWSConfigs.ApplicationName = ApplicationName;

            MobileAnalyticsManagerConfig config = new MobileAnalyticsManagerConfig();

            config.AllowUseDataNetwork = true;
            //config.DBWarningThreshold = 0.9f;
            config.MaxDBSize = 5242880 * 2;
            //config.MaxRequestSize = 102400;
            //config.SessionTimeout = 5;

            config.ClientContextConfiguration.Platform = "Windows";

            try
            {
                _manager = MobileAnalyticsManager.GetOrCreateInstance(AppId,                                   //Amazon Mobile Analytics App ID
                                                                      new CognitoAWSCredentials(CognitoPoolID, //Amazon Cognito Identity Pool ID
                                                                                                Amazon.RegionEndpoint.USEast1),
                                                                      Amazon.RegionEndpoint.USEast1, config);
            }
            catch (Exception ex)
            {
                Logger.LogMessage(typeof(Program), Logger.Severity.Error,
                                  "Failed to initialize MobileAnalyticsManager instance! Exception: " + ex);
                return(false);
            }

            return(true);
        }
        // Use this for initialization
        void Start()
        {
            UnityInitializer.AttachToGameObject(this.gameObject);

            AWSConfigs.HttpClient     = AWSConfigs.HttpClientOption.UnityWebRequest;
            AWSConfigs.RegionEndpoint = RegionEndpoint.APNortheast1;
            //AWSConfigs.HttpClient.

            _credentials = new CognitoAWSCredentials("ap-northeast-1:9ef21a6c-f1dd-4458-b771-7228a364e7ab", RegionEndpoint.APNortheast1);

            analyticsManager = MobileAnalyticsManager.GetOrCreateInstance("d1c5b82b0d93431289415c98693ab617", _credentials,
                                                                          RegionEndpoint.USEast1);

            CustomEvent customEvent = new CustomEvent("level_complete");

            customEvent.AddAttribute("LevelName", "Level1");
            customEvent.AddAttribute("CharacterClass", "Warrior");
            customEvent.AddAttribute("Successful", "True");
            customEvent.AddMetric("Score", 12345);
            customEvent.AddMetric("TimeInLevel", 64);

            analyticsManager.RecordEvent(customEvent);
        }
Пример #18
0
        public void TestErrorEventHandler()
        {
            string appID = TestRunner.StoredSettings.AppId;
            MobileAnalyticsManager manager = MobileAnalyticsManager.GetOrCreateInstance(appID, new CognitoAWSCredentials("wrong-cognito-pool-id", RegionEndpoint.USEast1), RegionEndpoint.USEast1);

            manager.MobileAnalyticsErrorEvent += errorHandler;
            CustomEvent customEvent = new CustomEvent("TestRecordEvent");

            customEvent.AddAttribute("LevelName", "Level5");
            customEvent.AddAttribute("Successful", "True");
            customEvent.AddMetric("Score", 12345);
            customEvent.AddMetric("TimeInLevel", 64);
            manager.RecordEvent(customEvent);
            Task.Delay(TimeSpan.FromSeconds(75)).Wait();
            lock (_lock)
            {
                Assert.IsTrue(resultList.Count > 0);
                foreach (bool result in resultList)
                {
                    Assert.IsTrue(result);
                }
            }
        }
Пример #19
0
        public void TestRecordEvent()
        {
            string appID = Guid.NewGuid().ToString();
            MobileAnalyticsManager manager    = MobileAnalyticsManager.GetOrCreateInstance(appID, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1);
            SQLiteEventStore       eventStore = new SQLiteEventStore(new MobileAnalyticsManagerConfig());

            try
            {
                CustomEvent customEvent = new CustomEvent("TestRecordEvent");
                customEvent.AddAttribute("LevelName", "Level5");
                customEvent.AddAttribute("Successful", "True");
                customEvent.AddMetric("Score", 12345);
                customEvent.AddMetric("TimeInLevel", 64);
                manager.RecordEvent(customEvent);

                MonetizationEvent monetizationEvent = new MonetizationEvent();
                monetizationEvent.Quantity           = 10.0;
                monetizationEvent.ItemPrice          = 2.00;
                monetizationEvent.ProductId          = "ProductId123";
                monetizationEvent.ItemPriceFormatted = "$2.00";
                monetizationEvent.Store         = "Amazon";
                monetizationEvent.TransactionId = "TransactionId123";
                monetizationEvent.Currency      = "USD";
                manager.RecordEvent(monetizationEvent);
            }
            catch (Exception e)
            {
                Console.WriteLine("Catch exception: " + e.ToString());
                Assert.Fail();
            }

            // sleep a while to make sure event is stored
            Task.Delay(TimeSpan.FromSeconds(1)).Wait();

            // Event store should have one custom event, one monetization event and one session start event.
            Assert.AreEqual(3, eventStore.NumberOfEvents(appID));
        }
Пример #20
0
        public void TestConstructor()
        {
            string appID1 = Guid.NewGuid().ToString();

            MobileAnalyticsManager.GetOrCreateInstance(appID1, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1);
            Assert.IsNotNull(MobileAnalyticsManager.GetInstance(appID1));

            string appID2 = Guid.NewGuid().ToString();

            MobileAnalyticsManager.GetOrCreateInstance(appID2, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());
            Assert.IsNotNull(MobileAnalyticsManager.GetInstance(appID2));

            string notInstantiatedID = Guid.NewGuid().ToString();

            try
            {
                MobileAnalyticsManager.GetInstance(notInstantiatedID);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.IsTrue(e is InvalidOperationException);
            }
        }
Пример #21
0
        public void TestConstructor()
        {
            string appID1 = Guid.NewGuid().ToString();

            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID1, Credentials, RegionEndpoint.USEast1);
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID1));

            string appID2 = Guid.NewGuid().ToString();

            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID2, Credentials, RegionEndpoint.USEast1, new MobileAnalyticsManagerConfig());
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID2));


            string notInstantiatedID = Guid.NewGuid().ToString();

            try
            {
                MobileAnalyticsManager.GetInstance(notInstantiatedID);
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.IsTrue(e is InvalidOperationException);
            }

#if BCL
            string appID3 = Guid.NewGuid().ToString();
            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID3);
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID3));


            string appID4 = Guid.NewGuid().ToString();
            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID4, Credentials);
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID4));

            string appID5 = Guid.NewGuid().ToString();
            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID5, RegionEndpoint.USEast1);
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID5));


            string appID6 = Guid.NewGuid().ToString();
            try
            {
                MobileAnalyticsManager.GetOrCreateInstance(appID6, new MobileAnalyticsManagerConfig());
            }
            catch (Exception e)
            {
                Console.WriteLine("get exception in constrctor :", e.ToString());
                Assert.Fail();
            }
            Assert.IsTrue(null != MobileAnalyticsManager.GetInstance(appID6));
#endif
        }
Пример #22
0
        public void TestSessionTimeout()
        {
            MobileAnalyticsManagerConfig maConfig = new MobileAnalyticsManagerConfig();

            Console.WriteLine("session delta is " + maConfig.SessionTimeout);

            string appID = Guid.NewGuid().ToString();

            // create AmazonMobileAnayticsManager instance
            MobileAnalyticsManager.GetOrCreateInstance(appID, CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1, maConfig);
            Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session session = new Amazon.MobileAnalytics.MobileAnalyticsManager.Internal.Session(appID, new MobileAnalyticsManagerConfig());
            session.Start();
            DateTime startTime1 = session.StartTime;
            string   sessionId1 = session.SessionId;

            // sleep for a while but wake up before session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout - 1)).Wait();
            session.Resume();

            // make sure session is not expired
            DateTime startTime2 = session.StartTime;
            string   sessionId2 = session.SessionId;

            Assert.IsTrue(startTime1 == startTime2);
            Assert.IsTrue(sessionId1 == sessionId2);

            // sleep longer until session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout + 1)).Wait();
            session.Resume();

            // make sure session is expired
            DateTime startTime3 = session.StartTime;
            string   sessionId3 = session.SessionId;

            Assert.IsTrue(startTime3 > startTime2);
            Assert.IsTrue(sessionId2 != sessionId3);

            // sleep for a while but wake up before session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout - 1)).Wait();
            session.Resume();

            // make sure session is not expired
            DateTime startTime4 = session.StartTime;
            string   sessionId4 = session.SessionId;

            Assert.IsTrue(startTime4 == startTime3);
            Assert.IsTrue(sessionId4 == sessionId3);

            // sleep longer until session expires
            session.Pause();
            Task.Delay(TimeSpan.FromSeconds(maConfig.SessionTimeout + 1)).Wait();
            session.Resume();

            // make sure session is expired
            DateTime startTime5 = session.StartTime;
            string   sessionId5 = session.SessionId;

            Assert.IsTrue(startTime5 > startTime4);
            Assert.IsTrue(sessionId5 != sessionId4);
        }
Пример #23
0
    // Use this for initialization
    void Start()
    {
        UnityInitializer.AttachToGameObject(this.gameObject);

        Debug.Log("mobileAppId::::" + mobileAppId);
        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;


        //AWS Mobile Analytics init
        analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(mobileAppId, new CognitoAWSCredentials(mobileIdentityPoolId, _Region), AnalyticsRegion);


        /*
         * Amazon Cognito
         * data synchronize
         *
         * // Open your datasets
         * userInfo = SyncManager.OpenOrCreateDataset("UserInfo");
         *
         * userInfo.OnSyncSuccess += SyncSuccessCallback;
         * userInfo.OnSyncFailure += SynFailure;
         *
         * // init user Info
         * loginTime = DateTime.Now.ToString();
         * float randomNum = UnityEngine.Random.Range(0f, 10.0f);
         * userId = getLoginId((int)randomNum);
         *
         * userInfo.Put("userId",userId);
         * userInfo.Put("loginTime",loginTime);
         *
         * Debug.Log("userId::::"+userId);
         * Debug.Log("loginTime::::" + loginTime);
         *
         * userInfo.SynchronizeAsync();
         */


        // Analystics For Custom Event
        CustomEvent customEvent = new CustomEvent("SceneLoading");

        customEvent.AddAttribute("SceneName", "Level1");
        customEvent.AddAttribute("CharacterClass", "Warrior");
        customEvent.AddAttribute("Successful", "True");
        customEvent.AddMetric("Score", 12345);
        customEvent.AddMetric("TimeInLevel", 64);

        analyticsManager.RecordEvent(customEvent);

        //Analystics For Common Event
        MonetizationEvent monetizationEvent = new MonetizationEvent();

        monetizationEvent.Quantity           = 3.0;
        monetizationEvent.ItemPrice          = 1.99;
        monetizationEvent.ProductId          = "ProductId123";
        monetizationEvent.ItemPriceFormatted = "$1.99";
        monetizationEvent.Store         = "Apple";
        monetizationEvent.TransactionId = "TransactionId123";
        monetizationEvent.Currency      = "USD";

        analyticsManager.RecordEvent(monetizationEvent);

        Debug.Log("SynchronizeAsync Called::::");

        // call scene 2
        StartCoroutine(LoadScene());
    }
Пример #24
0
 private void initCognitoAndAnalytics()
 {
     _credentials     = new CognitoAWSCredentials(IdentityPoolId, Amazon.RegionEndpoint.USEast1);
     analyticsManager = MobileAnalyticsManager.GetOrCreateInstance(_credentials, Amazon.RegionEndpoint.USEast1, AppId);
 }
Пример #25
0
 private MobileAnalyticsManager GetMobileAnalyticsManager(string appId)
 {
     return(MobileAnalyticsManager.GetOrCreateInstance(CommonTests.Framework.TestRunner.Credentials, RegionEndpoint.USEast1, appId, null));
 }