SetRevenue() public method

public SetRevenue ( double revenue, string currency ) : void
revenue double
currency string
return void
Ejemplo n.º 1
0
        public static void TrackEvent(string eventToken, double? revenue, string currency, List<string> callbackList, List<string> partnerList)
        {
            var adjustEvent = new AdjustEvent(eventToken);

            if (revenue.HasValue)
            {
                adjustEvent.SetRevenue(revenue.Value, currency);
            }

            if (callbackList != null)
            {
                for (int i = 0; i < callbackList.Count; i += 2)
                {
                    var key = callbackList[i];
                    var value = callbackList[i + 1];

                    adjustEvent.AddCallbackParameter(key, value);
                }
            }

            if (partnerList != null)
            {
                for (int i = 0; i < partnerList.Count; i += 2)
                {
                    var key = partnerList[i];
                    var value = partnerList[i + 1];

                    adjustEvent.AddPartnerParameter(key, value);
                }
            }

            Adjust.TrackEvent(adjustEvent);
        }
Ejemplo n.º 2
0
 private void btnRevenueEvent_Click(object sender, RoutedEventArgs e)
 {
     var revenueEvent = new AdjustEvent("{yourRevenueEventToken}");
     revenueEvent.SetRevenue(0.01, "EUR");
     Adjust.TrackEvent(revenueEvent);
 }
Ejemplo n.º 3
0
        public void TestEventsBuffered()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig("123456789012", AdjustConfig.EnvironmentSandbox);

            // buffer events
            config.EventBufferingEnabled = true;

            // start activity handler with config
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(AdjustConfig.EnvironmentSandbox, "Verbose", true);

            // test first session start
            CheckFirstSession();

            // create the first Event
            AdjustEvent firstEvent = new AdjustEvent("event1");

            // add callback parameters
            firstEvent.AddCallbackParameter("keyCall", "valueCall");
            firstEvent.AddCallbackParameter("keyCall", "valueCall2");
            firstEvent.AddCallbackParameter("fooCall", "barCall");

            // add partner paramters
            firstEvent.AddPartnerParameter("keyPartner", "valuePartner");
            firstEvent.AddPartnerParameter("keyPartner", "valuePartner2");
            firstEvent.AddPartnerParameter("fooPartner", "barPartner");

            // add revenue
            firstEvent.SetRevenue(0.001, "EUR");

            // track event
            activityHandler.TrackEvent(firstEvent);

            // create the second Event
            AdjustEvent secondEvent = new AdjustEvent("event2");

            // add empty revenue
            secondEvent.SetRevenue(0, "USD");

            // track second event
            activityHandler.TrackEvent(secondEvent);

            // create third Event
            AdjustEvent thirdEvent = new AdjustEvent("event3");

            // track third event
            activityHandler.TrackEvent(thirdEvent);

            DeviceUtil.Sleep(3000);

            // test first event
            // check that callback parameter was overwritten
            Assert.Warn("key keyCall was overwritten");

            // check that partner parameter was overwritten
            Assert.Warn("key keyPartner was overwritten");

            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event (0.00100 EUR, 'event1')");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // test second event
            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event (0.00000 USD, 'event2')");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // test third event
            // check that event package was added
            Assert.Test("PackageHandler AddPackage");

            // check that event was buffered
            Assert.Info("Buffered event 'event3'");

            // and not sent to package handler
            Assert.NotTest("PackageHandler SendFirstPackage");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");

            // check the number of activity packages
            // 1 session + 3 events
            Assert.AreEqual(4, MockPackageHandler.PackageQueue.Count);

            ActivityPackage firstSessionPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testFirstSessionPackage = new TestActivityPackage(firstSessionPackage);

            // set first session
            testFirstSessionPackage.TestSessionPackage(1);

            // first event
            ActivityPackage firstEventPackage = MockPackageHandler.PackageQueue[1];

            // create event package test
            TestActivityPackage testFirstEventPackage = new TestActivityPackage(firstEventPackage);

            // set event test parameters
            testFirstEventPackage.EventCount = "1";
            testFirstEventPackage.Suffix = "(0.00100 EUR, 'event1')";
            testFirstEventPackage.RevenueString = "0.00100";
            testFirstEventPackage.Currency = "EUR";
            testFirstEventPackage.CallbackParams = "{\"fooCall\":\"barCall\",\"keyCall\":\"valueCall2\"}";
            testFirstEventPackage.PartnerParams = "{\"keyPartner\":\"valuePartner2\",\"fooPartner\":\"barPartner\"}";

            // test first event
            testFirstEventPackage.TestEventPackage("event1");

            // second event
            ActivityPackage secondEventPackage = MockPackageHandler.PackageQueue[2];

            // create event package test
            TestActivityPackage testSecondEventPackage = new TestActivityPackage(secondEventPackage);

            // set event test parameters
            testSecondEventPackage.EventCount = "2";
            testSecondEventPackage.Suffix = "(0.00000 USD, 'event2')";
            testSecondEventPackage.RevenueString = "0.00000";
            testSecondEventPackage.Currency = "USD";

            // test second event
            testSecondEventPackage.TestEventPackage("event2");

            // third event
            ActivityPackage thirdEventPackage = MockPackageHandler.PackageQueue[3];

            // create event package test
            TestActivityPackage testThirdEventPackage = new TestActivityPackage(thirdEventPackage);

            // set event test parameters
            testThirdEventPackage.EventCount = "3";
            testThirdEventPackage.Suffix = "'event3'";

            // test third event
            testThirdEventPackage.TestEventPackage("event3");
        }
Ejemplo n.º 4
0
        public void testChecks()
        {
            // config with null app token
            AdjustConfig nullAppTokenConfig = new AdjustConfig(null, AdjustConfig.EnvironmentSandbox);

            Assert.Error("Missing App Token");
            Assert.IsFalse(nullAppTokenConfig.IsValid());

            // config with wrong size app token
            AdjustConfig oversizeAppTokenConfig = new AdjustConfig("1234567890123", AdjustConfig.EnvironmentSandbox);

            Assert.Error("Malformed App Token '1234567890123'");
            Assert.IsFalse(oversizeAppTokenConfig.IsValid());

            // config with null environment
            AdjustConfig nullEnvironmentConfig = new AdjustConfig("123456789012", null);

            Assert.Error("Missing environment");
            Assert.IsFalse(nullEnvironmentConfig.IsValid());

            // config with wrong environment
            AdjustConfig wrongEnvironmentConfig = new AdjustConfig("123456789012", "Other");

            Assert.Error("Unknown environment 'Other'");
            Assert.IsFalse(wrongEnvironmentConfig.IsValid());

            // start with null config
            ActivityHandler nullConfigactivityHandler = ActivityHandler.GetInstance(null, DeviceUtil);

            Assert.Error("AdjustConfig missing");
            Assert.Null(nullConfigactivityHandler);

            ActivityHandler invalidConfigactivityHandler = ActivityHandler.GetInstance(nullAppTokenConfig, DeviceUtil);

            Assert.Error("AdjustConfig not initialized correctly");
            Assert.Null(invalidConfigactivityHandler);

            // event with null event token
            AdjustEvent nullEventToken = new AdjustEvent(null);

            Assert.Error("Missing Event Token");
            Assert.IsFalse(nullEventToken.IsValid());

            // event with wrong size
            AdjustEvent wrongEventTokenSize = new AdjustEvent("eventXX");

            Assert.Error("Malformed Event Token 'eventXX'");
            Assert.IsFalse(wrongEventTokenSize.IsValid());

            // event
            AdjustEvent adjustEvent = new AdjustEvent("event1");

            // event with negative revenue
            adjustEvent.SetRevenue(-0.001, "EUR");

            Assert.Error("Invalid amount -0.001");

            // event with null currency
            adjustEvent.SetRevenue(0, null);

            Assert.Error("Currency must be set with revenue");

            // event with empty currency
            adjustEvent.SetRevenue(0, "");

            Assert.Error("Currency is empty");

            // callback parameter null key
            adjustEvent.AddCallbackParameter(null, "callValue");

            Assert.Error("Callback parameter key is missing");

            // callback parameter empty key
            adjustEvent.AddCallbackParameter("", "callValue");

            Assert.Error("Callback parameter key is empty");

            // callback parameter null value
            adjustEvent.AddCallbackParameter("keyCall", null);

            Assert.Error("Callback parameter value is missing");

            // callback parameter empty value
            adjustEvent.AddCallbackParameter("keyCall", "");

            Assert.Error("Callback parameter value is empty");

            // partner parameter null key
            adjustEvent.AddPartnerParameter(null, "callValue");

            Assert.Error("Partner parameter key is missing");

            // partner parameter empty key
            adjustEvent.AddPartnerParameter("", "callValue");

            Assert.Error("Partner parameter key is empty");

            // partner parameter null value
            adjustEvent.AddPartnerParameter("keyCall", null);

            Assert.Error("Partner parameter value is missing");

            // partner parameter empty value
            adjustEvent.AddPartnerParameter("keyCall", "");

            Assert.Error("Partner parameter value is empty");

            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Warn);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig("123456789012", AdjustConfig.EnvironmentSandbox);

            // create handler and start the first session
            ActivityHandler activityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(AdjustConfig.EnvironmentSandbox, "Warn", false);

            // test first session start
            CheckFirstSession();

            // track null event
            activityHandler.TrackEvent(null);
            DeviceUtil.Sleep(1000);

            Assert.Error("Event missing");

            activityHandler.TrackEvent(nullEventToken);
            DeviceUtil.Sleep(1000);

            Assert.Error("Event not initialized correctly");
        }