Пример #1
0
 public void LogError(string name, string title, string message)
 {
     if (Enabled && _manager != null)
     {
         var loggingEvent = new CustomEvent(Constants.Tracking.UserError);
         loggingEvent.AddAttribute(Constants.Tracking.UserErrorView, name);
         loggingEvent.AddAttribute(Constants.Tracking.UserErrorTitle, title);
         loggingEvent.AddAttribute(Constants.Tracking.UserErrorMessage, message);
         _manager.RecordEvent(loggingEvent);
     }
 }
Пример #2
0
 public void LogEvent(string name, string category, string eventName, string eventData)
 {
     if (Enabled && _manager != null)
     {
         var loggingEvent = new CustomEvent(name);
         loggingEvent.AddAttribute(Constants.Tracking.Category, category);
         loggingEvent.AddAttribute(Constants.Tracking.EventName, eventName);
         loggingEvent.AddAttribute(Constants.Tracking.EventData, eventData);
         _manager.RecordEvent(loggingEvent);
     }
 }
        partial void UIButton4_TouchUpInside(UIButton sender)
        {
            // Custom Event Buttoon Handler
            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);
        }
Пример #4
0
        partial void UIButton4_TouchUpInside(UIButton sender)
        {
            // Custom Event Buttoon Handler
            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);
        }
        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();
        }
Пример #7
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);
        }
Пример #8
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);
    }
Пример #9
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);
        }
        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);
        }
Пример #11
0
 public void LogViewHidden(string name)
 {
     if (Enabled && _manager != null)
     {
         var loggingEvent = new CustomEvent(Constants.Tracking.ViewHidden);
         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 RecordEvent(SinozeAnalyticsEvent e)
    {
        var c = new CustomEvent(e.Name);

        if(e._stringMetas != null)
            foreach(var a in e._stringMetas)
                c.AddAttribute(a.Key, a.Value);
        if(e._numberMetas != null)
            foreach(var m in e._numberMetas)
                c.AddMetric(m.Key, m.Value);

        analyticsManager.RecordEvent(c);
    }
        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();
        }
        // 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);
        }
Пример #16
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);
                }
            }
        }
Пример #17
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));
        }
Пример #18
0
 private void AddStoredGlobalAttributesAndMetricsToEvent(CustomEvent customEvent)
 {
     if (_sessionStorage != null)
     {
         if (_sessionStorage._globalAttributes != null)
         {
             foreach (var globalAttributePair in _sessionStorage._globalAttributes)
             {
                 customEvent.AddAttribute(globalAttributePair.Key, globalAttributePair.Value);
             }
         }
         if (_sessionStorage._globalMetrics != null)
         {
             foreach (var globalMetricPair in _sessionStorage._globalMetrics)
             {
                 customEvent.AddMetric(globalMetricPair.Key, globalMetricPair.Value);
             }
         }
     }
 }
Пример #19
0
        public void LogPerformance(string category, TimeSpan performanceCounter, Dictionary <string, string> values = null)
        {
            if (Enabled && _manager != null)
            {
                if (values == null)
                {
                    values = new Dictionary <string, string> ();
                }

                var loggingEvent = new CustomEvent(String.Format("Performance - {0}", category));
                loggingEvent.AddMetric("Duration", performanceCounter.TotalMilliseconds);

                foreach (var value in values)
                {
                    loggingEvent.AddAttribute(value.Key, value.Value);
                }

                _manager.RecordEvent(loggingEvent);
            }
        }
Пример #20
0
    public void logEvent(PlayerEvent label, bool midlevel, Dictionary <string, string> customAttributes = null, Dictionary <string, double> customMetrics = null)
    {
        if (!ENABLED)
        {
            return;
        }
        //Debug.Log("Logging custom event\n");

        CustomEvent customEvent = new CustomEvent("custom_event");


        customEvent.AddAttribute("eventtype", label.ToString());

        customEvent.AddMetric("level", Central.Instance.current_lvl);

        if (midlevel)
        {
            customEvent.AddMetric("health", Peripheral.Instance.GetHealth());
            customEvent.AddMetric("wave_time", Moon.Instance.TIME);
            customEvent.AddAttribute("difficulty", Peripheral.Instance.difficulty.ToString());
        }
        else
        {
            customEvent.AddMetric("wave_time", -1);
        }

        customEvent.AddAttribute("app_version", Application.version);

        customEvent.AddAttribute("device",
                                 SystemInfo.deviceType + " " + SystemInfo.deviceName + " " + SystemInfo.deviceModel);
        customEvent.AddAttribute("device_id", SystemInfo.deviceUniqueIdentifier);


        foreach (string key in customAttributes.Keys)
        {
            customEvent.AddAttribute(key, customAttributes[key].ToString());
        }

        foreach (string key in customMetrics.Keys)
        {
            customEvent.AddMetric(key, customMetrics[key]);
        }
        AnalyticsManager.RecordEvent(customEvent);
    }
Пример #21
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);
        }
Пример #22
0
 private void AddStoredGlobalAttributesAndMetricsToEvent(CustomEvent customEvent) {
     if (_sessionStorage != null) {
         if (_sessionStorage._globalAttributes != null) {
             foreach (var globalAttributePair in _sessionStorage._globalAttributes) {
                 customEvent.AddAttribute(globalAttributePair.Key, globalAttributePair.Value);
             }
         }
         if (_sessionStorage._globalMetrics != null) {
             foreach (var globalMetricPair in _sessionStorage._globalMetrics) {
                 customEvent.AddMetric(globalMetricPair.Key, globalMetricPair.Value);
             }
         }
     }
 }
Пример #23
0
        public void TestCustomEventConcurrency()
        {
            // event type
            const string EVENT_TYPE = "MyEventType";

            // attribute config
            string ATTR1        = "ATTR1";
            string ATTR1_VAL_T0 = "dshjadfhjdfa132`23jj`23jh1k2h3h21hg3h21j2gh";
            string ATTR1_VAL_T1 = "gfhfdhgvkfdkgljfdgjfdsj;l34t43jj4erjerb";
            string ATTR1_VAL_T2 = "7t32674tgdfjehkjdksjs;akfdshfjdsafkadsfdsljfa";

            string ATTR2        = "ATTR2";
            string ATTR2_VAL_T0 = "343hjfdshdfjklsafj0913432jh4";
            string ATTR2_VAL_T1 = "378t43y21ggdhsgdahshfdjsfafd";
            string ATTR2_VAL_T2 = "48ry42378tfhsfkds;kfl;dsdfk;ldslks";

            string ATTR3        = "ATTR3";
            string ATTR3_VAL_T0 = "321432g4ghjfjshdggfjhsdgfdskgfjdsjgfsd";
            string ATTR3_VAL_T1 = "76432tgrsgerhjkfgshdfdssfgjdssaf";
            string ATTR3_VAL_T2 = "87549353hjtkgdk;sfgfdgf;kfl;dshfjdsjkhfjs";

            string ATTR_EMPTY1 = "ATTR_EMPTY1";
            string ATTR_EMPTY2 = "ATTR_EMPTY2";
            string ATTR_EMPTY3 = "ATTR_EMPTY3";

            // metric config
            System.Random randObj        = new System.Random();
            const string  METRIC1        = "METRIC1";
            double        METRIC1_VAL_T0 = randObj.Next();
            double        METRIC1_VAL_T1 = randObj.Next();
            double        METRIC1_VAL_T2 = randObj.Next();

            const string METRIC2        = "METRIC2";
            double       METRIC2_VAL_T0 = randObj.Next();
            double       METRIC2_VAL_T1 = randObj.Next();
            double       METRIC2_VAL_T2 = randObj.Next();

            const string METRIC3        = "METRIC3";
            double       METRIC3_VAL_T0 = randObj.Next();
            double       METRIC3_VAL_T1 = randObj.Next();
            double       METRIC3_VAL_T2 = randObj.Next();


            CustomEvent customEvent = new CustomEvent(EVENT_TYPE);
            const int   LOOP_COUNT  = 999;

            Task task0 = new Task(() =>
            {
                for (int i = 0; i < LOOP_COUNT; i++)
                {
                    customEvent.AddAttribute(ATTR1, ATTR1_VAL_T0);
                    customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T0);
                    customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T0);

                    customEvent.AddMetric(METRIC1, METRIC1_VAL_T0);
                    customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T0);
                    customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T0);


                    customEvent.AddAttribute(ATTR_EMPTY1, "");
                    customEvent.AddGlobalAttribute(ATTR_EMPTY2, "");
                    customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR_EMPTY3, "");
                }
            });


            Task task1 = new Task(() =>
            {
                for (int i = 0; i < LOOP_COUNT; i++)
                {
                    customEvent.AddAttribute(ATTR1, ATTR1_VAL_T1);
                    customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T1);
                    customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T1);

                    customEvent.AddMetric(METRIC1, METRIC1_VAL_T1);
                    customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T1);
                    customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T1);
                }
            });


            Task task2 = new Task(() =>
            {
                for (int i = 0; i < LOOP_COUNT; i++)
                {
                    customEvent.AddAttribute(ATTR1, ATTR1_VAL_T1);
                    customEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T1);
                    customEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T1);

                    customEvent.AddMetric(METRIC1, METRIC1_VAL_T1);
                    customEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T1);
                    customEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T1);
                }
            });


            task0.Start();
            task1.Start();
            task2.Start();

            // wait all task complete
            Task.WaitAll(new[] { task0, task1, task2 });

            // Get Model event.
            Amazon.MobileAnalytics.Model.Event modelEvent = customEvent.ConvertToMobileAnalyticsModelEvent(GetMobileAnalyticsManager("TestCustomEventConcurrency").Session);

            // check attribute value
            if (!modelEvent.Attributes.ContainsKey(ATTR1) || !modelEvent.Attributes.ContainsKey(ATTR2) || !modelEvent.Attributes.ContainsKey(ATTR3))
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Attributes[ATTR1] != ATTR1_VAL_T0 && modelEvent.Attributes[ATTR1] != ATTR1_VAL_T1 && modelEvent.Attributes[ATTR1] != ATTR1_VAL_T2)
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Attributes[ATTR2] != ATTR2_VAL_T0 && modelEvent.Attributes[ATTR2] != ATTR2_VAL_T1 && modelEvent.Attributes[ATTR2] != ATTR2_VAL_T2)
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Attributes[ATTR3] != ATTR3_VAL_T0 && modelEvent.Attributes[ATTR3] != ATTR3_VAL_T1 && modelEvent.Attributes[ATTR3] != ATTR3_VAL_T2)
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Attributes[ATTR_EMPTY1] != "" || modelEvent.Attributes[ATTR_EMPTY2] != "" || modelEvent.Attributes[ATTR_EMPTY3] != "")
            {
                Assert.Fail();
                return;
            }


            // check metric value
            if (!modelEvent.Metrics.ContainsKey(METRIC1) || !modelEvent.Metrics.ContainsKey(METRIC2) || !modelEvent.Metrics.ContainsKey(METRIC3))
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Metrics[METRIC1] != METRIC1_VAL_T0 && modelEvent.Metrics[METRIC1] != METRIC1_VAL_T1 && modelEvent.Metrics[METRIC1] != METRIC1_VAL_T2)
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Metrics[METRIC2] != METRIC2_VAL_T0 && modelEvent.Metrics[METRIC2] != METRIC2_VAL_T1 && modelEvent.Metrics[METRIC2] != METRIC2_VAL_T2)
            {
                Assert.Fail();
                return;
            }

            if (modelEvent.Metrics[METRIC3] != METRIC3_VAL_T0 && modelEvent.Metrics[METRIC3] != METRIC3_VAL_T1 && modelEvent.Metrics[METRIC3] != METRIC3_VAL_T2)
            {
                Assert.Fail();
                return;
            }
        }
Пример #24
0
 public AmazonEventBuilder AddAttribute(string attributeName, string attributeValue)
 {
     customEvent.AddAttribute(attributeName, attributeValue);
     return(this);
 }
Пример #25
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());
    }