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(); }
public void RecordMonetizationEvent(MonetizationEvent evt) { Assert.IsNotNull(evt); if (m_analyticsManager == null) { return; } 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); }
partial void UIButton6_TouchUpInside(UIButton sender) { // Monetization Event Button Handler MonetizationEvent monetizationEvent = new MonetizationEvent(); monetizationEvent.Quantity = 10.0; monetizationEvent.ItemPrice = 2.00; monetizationEvent.ProductId = "ProductId123"; monetizationEvent.ItemPriceFormatted = "$2.00"; monetizationEvent.Store = "Apple"; monetizationEvent.TransactionId = "TransactionId123"; monetizationEvent.Currency = "USD"; Manager.RecordEvent(monetizationEvent); }
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); 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()); }
public void TestMonetizationEventConcurrency() { // event type const string EVENT_TYPE = "_monetization.purchase"; const double QUANTITY = 321321; const double ITEM_PRICE = 854584; const string PRODUCT_ID = "PRODUCT_ID123"; const string ITEM_PRICE_FORMATTED = "$1.99"; const string STORE = "STORE"; const string TRANSACTION_ID = "TRANSACTION_ID123"; const string CURRENCY = "2.22"; // attribute config const string ATTR1 = "ATTR1"; string ATTR1_VAL_T0 = Guid.NewGuid().ToString(); string ATTR1_VAL_T1 = Guid.NewGuid().ToString(); string ATTR1_VAL_T2 = Guid.NewGuid().ToString(); const string ATTR2 = "ATTR2"; string ATTR2_VAL_T0 = Guid.NewGuid().ToString(); string ATTR2_VAL_T1 = Guid.NewGuid().ToString(); string ATTR2_VAL_T2 = Guid.NewGuid().ToString(); const string ATTR3 = "ATTR3"; string ATTR3_VAL_T0 = Guid.NewGuid().ToString(); string ATTR3_VAL_T1 = Guid.NewGuid().ToString(); string ATTR3_VAL_T2 = Guid.NewGuid().ToString(); // 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(); MonetizationEvent monetizationEvent = new MonetizationEvent(); const int LOOP_COUNT = 1; Task task0 = new Task(() => { int i = 0; for (i = 0; i < LOOP_COUNT; i++) { monetizationEvent.AddAttribute(ATTR1, ATTR1_VAL_T0); monetizationEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T0); monetizationEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T0); monetizationEvent.AddMetric(METRIC1, METRIC1_VAL_T0); monetizationEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T0); monetizationEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T0); } monetizationEvent.Quantity = QUANTITY; monetizationEvent.ItemPrice = ITEM_PRICE; }); Task task1 = new Task(() => { int i = 0; for (i = 0; i < LOOP_COUNT; i++) { monetizationEvent.AddAttribute(ATTR1, ATTR1_VAL_T1); monetizationEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T1); monetizationEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T1); monetizationEvent.AddMetric(METRIC1, METRIC1_VAL_T1); monetizationEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T1); monetizationEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T1); } monetizationEvent.ProductId = PRODUCT_ID; monetizationEvent.ItemPriceFormatted = ITEM_PRICE_FORMATTED; monetizationEvent.Store = STORE; monetizationEvent.TransactionId = TRANSACTION_ID; monetizationEvent.Currency = CURRENCY; }); Task task2 = new Task(() => { int i = 0; for (i = 0; i < LOOP_COUNT; i++) { monetizationEvent.AddAttribute(ATTR1, ATTR1_VAL_T2); monetizationEvent.AddGlobalAttribute(ATTR2, ATTR2_VAL_T2); monetizationEvent.AddGlobalAttribute(EVENT_TYPE, ATTR3, ATTR3_VAL_T2); monetizationEvent.AddMetric(METRIC1, METRIC1_VAL_T2); monetizationEvent.AddGlobalMetric(METRIC2, METRIC2_VAL_T2); monetizationEvent.AddGlobalMetric(EVENT_TYPE, METRIC3, METRIC3_VAL_T2); } }); task0.Start(); task1.Start(); task2.Start(); // wait all task complete Task.WaitAll(new[] { task0, task1, task2 }); // Get model event. Amazon.MobileAnalytics.Model.Event modelEvent = monetizationEvent.ConvertToMobileAnalyticsModelEvent(GetMobileAnalyticsManager("TestMonetizationEventConcurrency").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; } // 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; } // metric name const string PURCHASE_EVENT_QUANTITY_METRIC = "_quantity"; const string PURCHASE_EVENT_ITEM_PRICE_METRIC = "_item_price"; // attribute name const string PURCHASE_EVENT_PRODUCT_ID_ATTR = "_product_id"; const string PURCHASE_EVENT_ITEM_PRICE_FORMATTED_ATTR = "_item_price_formatted"; const string PURCHASE_EVENT_STORE_ATTR = "_store"; const string PURCHASE_EVENT_TRANSACTION_ID_ATTR = "_transaction_id"; const string PURCHASE_EVENT_CURRENCY_ATTR = "_currency"; if (modelEvent.Metrics[PURCHASE_EVENT_QUANTITY_METRIC] != QUANTITY || modelEvent.Metrics[PURCHASE_EVENT_ITEM_PRICE_METRIC] != ITEM_PRICE) { Assert.Fail(); return; } if (modelEvent.Attributes[PURCHASE_EVENT_PRODUCT_ID_ATTR] != PRODUCT_ID || modelEvent.Attributes[PURCHASE_EVENT_ITEM_PRICE_FORMATTED_ATTR] != ITEM_PRICE_FORMATTED || modelEvent.Attributes[PURCHASE_EVENT_STORE_ATTR] != STORE || modelEvent.Attributes[PURCHASE_EVENT_TRANSACTION_ID_ATTR] != TRANSACTION_ID || modelEvent.Attributes[PURCHASE_EVENT_CURRENCY_ATTR] != CURRENCY) { Assert.Fail(); return; } }