public void RecordCustomEvent(string name, Dictionary <string, string> attributes, Dictionary <string, double> metrics)
        {
            Assert.IsFalse(string.IsNullOrEmpty(name));

            if (m_analyticsManager == null)
            {
                return;
            }

            CustomEvent evt = new CustomEvent(name);

            if (attributes != null)
            {
                foreach (var att in attributes)
                {
                    evt.AddAttribute(att.Key, att.Value);
                }
            }

            if (metrics != null)
            {
                foreach (var metric in metrics)
                {
                    evt.AddMetric(metric.Key, metric.Value);
                }
            }

            m_analyticsManager.RecordEvent(evt);
        }
        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();
        }
        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);
        }
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(0, 0, Screen.width * 0.5f, Screen.height));
            GUILayout.Label("Amazon Mobile Analytics Operations");

            // record custom event
            if (GUILayout.Button("Record Custom Event", GUILayout.MinHeight(Screen.height * 0.2f), GUILayout.Width(Screen.width * 0.4f)))
            {
            }

            // record monetization event
            if (GUILayout.Button("Record Monetization Event", GUILayout.MinHeight(Screen.height * 0.2f), GUILayout.Width(Screen.width * 0.4f)))
            {
                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);
            }


            GUILayout.EndArea();
        }
Beispiel #6
0
 public void LogViewLoaded(string name)
 {
     if (Enabled && _manager != null)
     {
         var loggingEvent = new CustomEvent(Constants.Tracking.ViewLoaded);
         loggingEvent.AddAttribute(Constants.Tracking.ViewName, name);
         _manager.RecordEvent(loggingEvent);
     }
 }
        void OnGUI()
        {
            GUILayout.BeginArea(new Rect(0, 0, Screen.width * 0.5f, Screen.height));
            GUILayout.Label("Amazon Mobile Analytics Operations");

            // record custom event
            if (GUILayout.Button("Record Custom Event", GUILayout.MinHeight(Screen.height * 0.2f), GUILayout.Width(Screen.width * 0.4f)))
            {
                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);
            }

            // record monetization event
            if (GUILayout.Button("Record Monetization Event", GUILayout.MinHeight(Screen.height * 0.2f), GUILayout.Width(Screen.width * 0.4f)))
            {
                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);
            }


            GUILayout.EndArea();
        }
        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));
        }
    // 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);
    }
        // 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);
        }
        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);
                }
            }
        }
    // 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());
    }
Beispiel #13
0
 public void RecordEvent(CustomEvent customEvent)
 {
     analyticsManager.RecordEvent(customEvent);
 }
Beispiel #14
0
        private static bool ParseAndSendAnalyticsEvent(String EventDataFile)
        {
            Logger.LogMessage(typeof(Program), Logger.Severity.Info,
                              "Begin to parse event message file: " + EventDataFile);

            try
            {
                //step1: read event data content from event message file
                StreamReader sr = new StreamReader(EventDataFile);
                Byte[]       AWSAnalyticsEventData = Encoding.UTF8.GetBytes(sr.ReadLine());
                sr.Close();
                sr.Dispose();

                //step2: deserialize the event data content to AWSAnalyticsEvent object
                DataContractJsonSerializer js   = new DataContractJsonSerializer(typeof(InFocusAnalyticsEvent));
                MemoryStream          stream    = new MemoryStream(AWSAnalyticsEventData);
                InFocusAnalyticsEvent EventBean = (InFocusAnalyticsEvent)js.ReadObject(stream);
                stream.Close();
                stream.Dispose();

                Console.WriteLine("get CustomEvent: " + EventBean.EventName);
                Logger.LogMessage(typeof(Program), Logger.Severity.Info,
                                  "get CustomEvent: EventName is " + EventBean.EventName);

                //step3: initialize CustomEvent object from AWSAnalyticsEvent object
                CustomEvent customEvent = new CustomEvent(EventBean.EventName);

                customEvent.AddAttribute("EventTime", EventBean.EventTime);

                if (EventBean.AttributeMap != null)
                {
                    foreach (KeyValuePair <string, string> attribute in EventBean.AttributeMap)
                    {
                        customEvent.AddAttribute(attribute.Key, attribute.Value);
                    }
                }

                if (EventBean.MetricMap != null)
                {
                    foreach (KeyValuePair <string, Double> attribute in EventBean.MetricMap)
                    {
                        customEvent.AddMetric(attribute.Key, attribute.Value);
                    }
                }

                //step4: record event which will be automatically submitted later.
                _manager.RecordEvent(customEvent);
                Logger.LogMessage(typeof(Program), Logger.Severity.Info,
                                  "Now, a background thread will send AWS Events later!");

                //step5: delete this used event message file
                System.IO.File.Delete(EventDataFile);
                Logger.LogMessage(typeof(Program), Logger.Severity.Info,
                                  "Now, deleted event message file " + EventDataFile);
            }
            catch (Exception ex)
            {
                Logger.LogMessage(typeof(Program), Logger.Severity.Error,
                                  "Failed to Read and Parse AWS Analytics Event Data from file " + EventDataFile + "!. Exception:" + ex);

                return(false);
            }

            return(true);
        }