示例#1
0
        public static void ApplicationLaunching(string appToken, string environment, string logLevelString, string defaultTracker, bool? eventBufferingEnabled, string sdkPrefix, Action<Dictionary<string, string>> attributionChangedDic)
        {
            LogLevel logLevel;
            if (Enum.TryParse(logLevelString, out logLevel))
            {
                Adjust.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                    logLevel: logLevel);
            }
            else
            {
                Adjust.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg));
            }

            var config = new AdjustConfig(appToken, environment);

            config.DefaultTracker = defaultTracker;

            if (eventBufferingEnabled.HasValue)
            {
                config.EventBufferingEnabled = eventBufferingEnabled.Value;
            }

            config.SdkPrefix = sdkPrefix;

            if (attributionChangedDic != null)
            {
                config.AttributionChanged = (attribution) => attributionChangedDic(attribution.ToDictionary());
            }

            Adjust.ApplicationLaunching(config);
        }
示例#2
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // setup logging
            Adjust.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

            // configure Adjust
            var config = new AdjustConfig("{yourAppToken}", AdjustConfig.EnvironmentSandbox);

            // enable event buffering
            //config.EventBufferingEnabled = true;

            // set default tracker
            //config.DefaultTracker = "{YourDefaultTracker}";

            // set attribution delegate
            config.AttributionChanged = (attribution) =>
                System.Diagnostics.Debug.WriteLine("attribution: " + attribution);

            Adjust.ApplicationLaunching(config);

            // put the SDK in offline mode
            //Adjust.SetOfflineMode(offlineMode: true);

            // disable the SDK
            //Adjust.SetEnabled(enabled: false);

            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard XAML initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Language display initialization
            InitializeLanguage();

            // Show graphics profiling information while debugging.
            if (Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Prevent the screen from turning off while under the debugger by disabling
                // the application's idle detection.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }
        }
示例#3
0
 public static void ApplicationLaunching(AdjustConfig adjustConfig)
 {
     if (ApplicationLaunched)
     {
         return;
     }
     AdjustInstance.ApplicationLaunching(adjustConfig, DeviceUtil);
     RegisterLifecycleEvents();
 }
示例#4
0
 /// <summary>
 ///  Tell Adjust that the application was launched.
 ///
 ///  This is required to initialize Adjust. Call this in the Application_Launching
 ///  method of your Windows.UI.Xaml.Application class.
 /// </summary>
 /// <param name="adjustConfig">
 ///   The object that configures the adjust SDK. <seealso cref="AdjustConfig"/>
 /// </param>
 public static void ApplicationLaunching(AdjustConfig adjustConfig)
 {
     AdjustInstance.ApplicationLaunching(adjustConfig, DeviceUtil);
     try
     {
         Window.Current.CoreWindow.VisibilityChanged += VisibilityChanged;
     }
     catch (Exception)
     {
         AdjustFactory.Logger.Debug("Not possible to detect automatically if the app goes to the background");
     }
 }
示例#5
0
 /// <summary>
 ///  Tell Adjust that the application was launched.
 ///
 ///  This is required to initialize Adjust. Call this in the Application_Launching
 ///  method of your Windows.UI.Xaml.Application class.
 /// </summary>
 /// <param name="adjustConfig">
 ///   The object that configures the adjust SDK. <seealso cref="AdjustConfig"/>
 /// </param>
 public static void ApplicationLaunching(AdjustConfig adjustConfig)
 {
     AdjustInstance.ApplicationLaunching(adjustConfig, DeviceUtil);
     try
     {
         Window.Current.CoreWindow.VisibilityChanged += VisibilityChanged;
     }
     catch (Exception)
     {
         AdjustFactory.Logger.Debug("Not possible to detect automatically if the app goes to the background");
     }
 }
示例#6
0
        public void TestSessions()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Info);

            // adjust the session intervals for testing
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,4000));
            AdjustFactory.SetSubsessionInterval(new TimeSpan(0,0,0,0,1000));

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

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

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests("sandbox", "Info", false);

            // test first session start
            CheckFirstSession();

            // trigger a new sub session session
            activityHandler.TrackSubsessionStart();

            // and end it
            activityHandler.TrackSubsessionEnd();

            DeviceUtil.Sleep(5000);

            // test the new sub session
            CheckSubsession(
                sessionCount: 1,
                subsessionCount: 2,
                timerAlreadyStarted: true);

            // test the end of the subsession
            CheckEndSession();

            // trigger a new session
            activityHandler.TrackSubsessionStart();

            DeviceUtil.Sleep(1000);

            // new session
            CheckNewSession(
                paused:false,
                sessionCount: 2,
                eventCount: 0,
                timerAlreadyStarted: true);

            // end the session
            activityHandler.TrackSubsessionEnd();

            DeviceUtil.Sleep(1000);

            // 2 session packages
            Assert.AreEqual(2, MockPackageHandler.PackageQueue.Count);

            ActivityPackage firstSessionActivityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testFirstSessionActivityPackage = new TestActivityPackage(firstSessionActivityPackage);

            // test first session
            testFirstSessionActivityPackage.TestSessionPackage(1);

            // get second session package
            ActivityPackage secondSessionActivityPackage = MockPackageHandler.PackageQueue[1];

            // create second session test package
            TestActivityPackage testSecondSessionActivityPackage = new TestActivityPackage(secondSessionActivityPackage);

            // check if it saved the second subsession in the new package
            testSecondSessionActivityPackage.SubsessionCount = 2;

            // test second session
            testSecondSessionActivityPackage.TestSessionPackage(2);
        }
示例#7
0
        public void TestUpdateAttribution()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

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

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

            DeviceUtil.Sleep(2000);

            // test init values
            InitTests(environment: "sandbox", logLevel: "Verbose");

            // test first session start
            CheckFirstSession();

            string nullJsonString = null;

            AdjustAttribution nullAttribution = AdjustAttribution.FromJsonString(nullJsonString);

            // check if Attribution wasn't built
            Assert.Null(nullAttribution);

            // check that it does not update a null attribution
            Assert.IsFalse(firstActivityHandler.UpdateAttribution(nullAttribution));

            // create an empty attribution
            var emptyJsonString = "{ }";
            AdjustAttribution emptyAttribution = AdjustAttribution.FromJsonString(emptyJsonString);

            // check that updates attribution
            Assert.IsTrue(firstActivityHandler.UpdateAttribution(emptyAttribution));
            DeviceUtil.Sleep(2000);
            Assert.Debug("Wrote Attribution: tt:Null tn:Null net:Null cam:Null adg:Null cre:Null cl:Null");

            emptyAttribution = AdjustAttribution.FromJsonString(emptyJsonString);

            // check that it does not update the attribution
            Assert.IsFalse(firstActivityHandler.UpdateAttribution(emptyAttribution));
            DeviceUtil.Sleep(2000);
            Assert.NotDebug("Wrote Attribution");

            // end session
            firstActivityHandler.TrackSubsessionEnd();
            DeviceUtil.Sleep(2000);

            CheckEndSession();

            config = new AdjustConfig(appToken: "123456789012", environment: AdjustConfig.EnvironmentSandbox);

            config.AttributionChanged = (attribution) => MockLogger.Test("onAttributionChanged: {0}", attribution);

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

            ActivityHandler restartActivityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(environment: "sandbox", logLevel: "Debug",
                readActivityState: "ec:0 sc:1 ssc:1",
                readAttribution: "tt:Null tn:Null net:Null cam:Null adg:Null cre:Null cl:Null");

            CheckSubsession(subsessionCount: 2);

            // check that it does not update the attribution after the restart
            Assert.IsFalse(restartActivityHandler.UpdateAttribution(emptyAttribution));
            Assert.NotDebug("Wrote Attribution");

            // new attribution
            var firstAttributionJsonString = "{ " +
                        "\"tracker_token\" : \"ttValue\" , " +
                        "\"tracker_name\"  : \"tnValue\" , " +
                        "\"network\"       : \"nValue\" , " +
                        "\"campaign\"      : \"cpValue\" , " +
                        "\"adgroup\"       : \"aValue\" , " +
                        "\"creative\"      : \"ctValue\" , " +
                        "\"click_label\"   : \"clValue\" }";
            AdjustAttribution firstAttribution = AdjustAttribution.FromJsonString(firstAttributionJsonString);

            //check that it updates
            Assert.IsTrue(restartActivityHandler.UpdateAttribution(firstAttribution));

            DeviceUtil.Sleep(2000);
            Assert.Debug("Wrote Attribution: tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue cl:clValue");

            // check that it launch the saved attribute if it's not WP8.0
            if (TargetPlatform != Pcl.TargetPlatform.wphone80)
            {
                Assert.Test("onAttributionChanged: tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue cl:clValue");
            }

            // check that it does not update the attribution
            Assert.IsFalse(restartActivityHandler.UpdateAttribution(firstAttribution));

            DeviceUtil.Sleep(2000);
            Assert.NotDebug("Wrote Attribution");

            // end session
            restartActivityHandler.TrackSubsessionEnd();
            DeviceUtil.Sleep(2000);

            CheckEndSession();

            config = new AdjustConfig(appToken: "123456789012", environment: AdjustConfig.EnvironmentSandbox);

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

            config.AttributionChanged = (attribution) => MockLogger.Test("onAttributionChanged: {0}", attribution);

            ActivityHandler secondRestartActivityHandler = GetActivityHandler(config);

            DeviceUtil.Sleep(2000);

            // test init values
            InitTests(environment: "sandbox" , logLevel:"Info",
                readActivityState: "ec:0 sc:1 ssc:2",
                readAttribution: "tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue cl:clValue");

            CheckSubsession(subsessionCount: 3);

            // check that it does not update the attribution after the restart
            Assert.IsFalse(secondRestartActivityHandler.UpdateAttribution(firstAttribution));
            DeviceUtil.Sleep(2000);
            Assert.NotDebug("Wrote Attribution");

            // new attribution
            var secondAttributionJson = "{ " +
                        "\"tracker_token\" : \"ttValue2\" , " +
                        "\"tracker_name\"  : \"tnValue2\" , " +
                        "\"network\"       : \"nValue2\" , " +
                        "\"campaign\"      : \"cpValue2\" , " +
                        "\"adgroup\"       : \"aValue2\" , " +
                        "\"creative\"      : \"ctValue2\" , " +
                        "\"click_label\"   : \"clValue2\" }";

            AdjustAttribution secondAttribution = AdjustAttribution.FromJsonString(secondAttributionJson);

            //check that it updates
            Assert.IsTrue(secondRestartActivityHandler.UpdateAttribution(secondAttribution));
            DeviceUtil.Sleep(2000);
            Assert.Debug("Wrote Attribution: tt:ttValue2 tn:tnValue2 net:nValue2 cam:cpValue2 adg:aValue2 cre:ctValue2 cl:clValue2");

            // check that it launch the saved attribute
            if (TargetPlatform != Pcl.TargetPlatform.wphone80)
            {
                Assert.Test("onAttributionChanged: tt:ttValue2 tn:tnValue2 net:nValue2 cam:cpValue2 adg:aValue2 cre:ctValue2 cl:clValue2");
            }
            // check that it does not update the attribution
            Assert.IsFalse(secondRestartActivityHandler.UpdateAttribution(secondAttribution));
            DeviceUtil.Sleep(2000);
            Assert.NotDebug("Wrote Attribution");
        }
示例#8
0
 /// <summary>
 ///  Tell Adjust that the application was launched.
 ///
 ///  This is required to initialize Adjust. Call this in the Application_Launching
 ///  method of your System.Windows.Application class.
 /// </summary>
 /// <param name="adjustConfig">
 ///   The object that configures the adjust SDK. <seealso cref="AdjustConfig"/>
 /// </param>
 public static void ApplicationLaunching(AdjustConfig adjustConfig)
 {
     AdjustInstance.ApplicationLaunching(adjustConfig, DeviceUtil);
 }
示例#9
0
        public void TestCheckAttributionState()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

            //AdjustFactory.setTimerStart(500);
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,4000));
            /***
             * // if it's a new session
             * if (ActivityState.SubSessionCount <= 1) { return; }
             *
             * // if there is already an attribution saved and there was no attribution being asked
             * if (Attribution != null && !ActivityState.AskingAttribution) { return; }
             *
             * AttributionHandler.AskAttribution();
             */

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

            config.AttributionChanged = (adjustAttribution) => MockLogger.Test("AttributionChanged: {0}", adjustAttribution);

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

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests();

            // subsession count is 1
            // attribution is null,
            // askingAttribution is false by default,
            // -> Not called

            // test first session start
            CheckFirstSession();

            // test that get attribution wasn't called
            Assert.NotTest("AttributionHandler AskAttribution");

            // subsession count increased to 2
            // attribution is still null,
            // askingAttribution is still false,
            // -> Called

            // trigger a new sub session
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount:1, subsessionCount: 2,
                timerAlreadyStarted: true, askAttributionIsCalled: true);

            // subsession count increased to 3
            // attribution is still null,
            // askingAttribution is set to true,
            // -> Called

            // set asking attribution
            activityHandler.SetAskingAttribution(true);
            DeviceUtil.Sleep(1000);
            Assert.Debug("Wrote Activity state: ec:0 sc:1 ssc:2");

            // trigger a new session
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount: 1, subsessionCount: 3,
                timerAlreadyStarted: true, askAttributionIsCalled: true);

            // subsession is reset to 1 with new session
            // attribution is still null,
            // askingAttribution is set to true,
            // -> Not called

            DeviceUtil.Sleep(3000); // 5 seconds = 2 + 3
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount: 2, subsessionCount: 1,
                timerAlreadyStarted: true, askAttributionIsCalled: false);

            // subsession count increased to 2
            // attribution is set,
            // askingAttribution is set to true,
            // -> Called
            var jsonAttribution = "{ " +
                        "\"tracker_token\" : \"ttValue\" , " +
                        "\"tracker_name\"  : \"tnValue\" , " +
                        "\"network\"       : \"nValue\" , " +
                        "\"campaign\"      : \"cpValue\" , " +
                        "\"adgroup\"       : \"aValue\" , " +
                        "\"creative\"      : \"ctValue\" , " +
                        "\"click_label\"   : \"clValue\" }";

            var attribution = AdjustAttribution.FromJsonString(jsonAttribution);

            // update the attribution
            Assert.IsTrue(activityHandler.UpdateAttribution(attribution));

            DeviceUtil.Sleep(1000);
            // attribution was updated
            Assert.Debug("Wrote Attribution: tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue cl:clValue");

            // trigger a new sub session
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(2, 2, true, true);
            // subsession count is reset to 1
            // attribution is set,
            // askingAttribution is set to true,
            // -> Not called

            DeviceUtil.Sleep(3000); // 5 seconds = 2 + 3
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount: 3, subsessionCount: 1,
                timerAlreadyStarted: true, askAttributionIsCalled: false);

            // subsession increased to 2
            // attribution is set,
            // askingAttribution is set to false
            // -> Not called

            activityHandler.SetAskingAttribution(false);
            DeviceUtil.Sleep(1000);
            Assert.Debug("Wrote Activity state: ec:0 sc:3 ssc:1");

            // trigger a new sub session
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount: 3, subsessionCount: 2,
                timerAlreadyStarted: true, askAttributionIsCalled: false);

            // subsession is reset to 1
            // attribution is set,
            // askingAttribution is set to false
            // -> Not called

            DeviceUtil.Sleep(3000); // 5 seconds = 2 + 3
            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(2000);

            CheckSubsession(sessionCount: 4, subsessionCount: 1,
                timerAlreadyStarted: true, askAttributionIsCalled: false);
        }
示例#10
0
        public void TestFinishedTrackingActivity()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Verbose);

            // create the config to start the session
            AdjustConfig config = new AdjustConfig(appToken: "123456789012", environment: AdjustConfig.EnvironmentProduction);

            config.AttributionChanged = (attribution) => MockLogger.Test("AttributionChanged: {0}", attribution);

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

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(environment: "production" , logLevel: "Assert");

            // test first session start
            CheckFirstSession();

            Dictionary<string, string> responseNull = null;

            activityHandler.FinishedTrackingActivity(responseNull);
            DeviceUtil.Sleep(1000);

            // if the response is null
            Assert.NotError("Malformed deeplink");
            Assert.NotInfo("Open deep link");

            // set package handler to respond with a valid attribution
            var malformedDeeplinkResponse = new Dictionary<string, string> {{"deeplink" , "<malformedUrl>"}};

            activityHandler.FinishedTrackingActivity(malformedDeeplinkResponse);
            DeviceUtil.Sleep(1000);

            // check that it was unable to open the url
            Assert.Error("Malformed deeplink '<malformedUrl>'");

            // checking the default values of the first session package
            // should only have one package
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            ActivityPackage activityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testActivityPackage = new TestActivityPackage(activityPackage)
            {
                NeedsAttributionData = true,
                Environment = "production",
            };

            // set first session
            testActivityPackage.TestSessionPackage(sessionCount: 1);
        }
示例#11
0
        public void TestEventsNotBuffered()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Debug);

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

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

            DeviceUtil.Sleep(3000);

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

            // test first session start
            CheckFirstSession();

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

            // track event
            activityHandler.TrackEvent(firstEvent);

            DeviceUtil.Sleep(2000);

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

            // check that event was sent to package handler
            Assert.Test("PackageHandler SendFirstPackage");

            // and not buffered
            Assert.NotInfo("Buffered event");

            // after tracking the event it should write the activity state
            Assert.Debug("Wrote Activity state");
        }
示例#12
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");
        }
示例#13
0
        public void TestDisable()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Error);

            // adjust the session intervals for testing
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,4000));
            AdjustFactory.SetSubsessionInterval(new TimeSpan(0,0,0,0,1000));

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

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

            // check that is true by default
            Assert.IsTrue(activityHandler.IsEnabled());

            // disable sdk
            activityHandler.SetEnabled(false);

            // check that it is disabled
            Assert.IsFalse(activityHandler.IsEnabled());

            // not writing activity state because it did not had time to start
            Assert.NotDebug("Wrote Activity state");

            // check if message the disable of the SDK
            Assert.Info("Pausing package and attribution handler to disable the SDK");

            // it's necessary to sleep the activity for a while after each handler call
            // to let the internal queue act
            DeviceUtil.Sleep(2000);

            // test init values
            InitTests(environment: "sandbox", logLevel: "Error");

            // test first session start without attribution handler
            CheckFirstSession(paused: true);

            // test end session of disable
            CheckEndSession();

            // try to do activities while SDK disabled
            activityHandler.TrackSubsessionStart();
            activityHandler.TrackEvent(new AdjustEvent("event1"));

            DeviceUtil.Sleep(3000);

            // check that timer was not executed
            CheckTimerIsFired(false);

            // check that it did not resume
            Assert.NotTest("PackageHandler ResumeSending");

            // check that it did not wrote activity state from new session or subsession
            Assert.NotDebug("Wrote Activity state");

            // check that it did not add any event package
            Assert.NotTest("PackageHandler AddPackage");

            // only the first session package should be sent
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            // put in offline mode
            activityHandler.SetOfflineMode(true);

            // pausing due to offline mode
            Assert.Info("Pausing package and attribution handler to put in offline mode");

            // wait to update status
            DeviceUtil.Sleep(6000);

            // test end session of offline
            CheckEndSession(updateActivityState: false);

            // re-enable the SDK
            activityHandler.SetEnabled(true);

            // check that it is enabled
            Assert.IsTrue(activityHandler.IsEnabled());

            // check message of SDK still paused
            Assert.Info("Package and attribution handler remain paused due to the SDK is offline");

            activityHandler.TrackSubsessionStart();
            DeviceUtil.Sleep(1000);

            CheckNewSession(paused: true, sessionCount: 2);

            // and that the timer is not fired
            CheckTimerIsFired(false);

            // track an event
            activityHandler.TrackEvent(new AdjustEvent("event1"));

            // and that the timer is not fired
            DeviceUtil.Sleep(1000);

            // check that it did add the event package
            Assert.Test("PackageHandler AddPackage");

            // and send it
            Assert.Test("PackageHandler SendFirstPackage");

            // it should have the second session and the event
            Assert.AreEqual(3, MockPackageHandler.PackageQueue.Count);

            ActivityPackage secondSessionPackage = MockPackageHandler.PackageQueue[1];

            // create activity package test
            TestActivityPackage testSecondSessionPackage = new TestActivityPackage(secondSessionPackage);

            // set the sub sessions
            testSecondSessionPackage.SubsessionCount = 1;

            // test second session
            testSecondSessionPackage.TestSessionPackage(sessionCount: 2);

            ActivityPackage eventPackage = MockPackageHandler.PackageQueue[2];

            // create activity package test
            TestActivityPackage testEventPackage = new TestActivityPackage(eventPackage);

            testEventPackage.Suffix = "'event1'";

            // test event
            testEventPackage.TestEventPackage(eventToken: "event1");

            // put in online mode
            activityHandler.SetOfflineMode(false);

            // message that is finally resuming
            Assert.Info("Resuming package and attribution handler to put in online mode");

            DeviceUtil.Sleep(6000);

            // check status update
            Assert.Test("AttributionHandler ResumeSending");
            Assert.Test("PackageHandler ResumeSending");

            // track sub session
            activityHandler.TrackSubsessionStart();

            DeviceUtil.Sleep(1000);

            // test session not paused
            CheckNewSession(paused: false, sessionCount: 3, eventCount: 1, timerAlreadyStarted: true);
        }
示例#14
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");
        }
示例#15
0
        private ActivityHandler GetActivityHandler(AdjustConfig config)
        {
            ActivityHandler activityHandler = ActivityHandler.GetInstance(config, DeviceUtil);

            return activityHandler;
        }
示例#16
0
 /// <summary>
 ///  Tell Adjust that the application was launched.
 ///
 ///  This is required to initialize Adjust. Call this in the Application_Launching
 ///  method of your System.Windows.Application class.
 /// </summary>
 /// <param name="adjustConfig">
 ///   The object that configures the adjust SDK. <seealso cref="AdjustConfig"/>
 /// </param>
 public static void ApplicationLaunching(AdjustConfig adjustConfig)
 {
     AdjustInstance.ApplicationLaunching(adjustConfig, DeviceUtil);
 }
示例#17
0
        public void TestFirstSession()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

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

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

            DeviceUtil.Sleep(3000);

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

            // test first session start
            CheckFirstSession();

            // checking the default values of the first session package
            // should only have one package
            Assert.AreEqual(1, MockPackageHandler.PackageQueue.Count);

            ActivityPackage activityPackage = MockPackageHandler.PackageQueue[0];

            // create activity package test
            TestActivityPackage testActivityPackage = new TestActivityPackage(activityPackage);

            // set first session
            testActivityPackage.TestSessionPackage(1);
        }
示例#18
0
        public void TestOfflineMode()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

            // adjust the session intervals for testing
            AdjustFactory.SetSessionInterval(new TimeSpan(0,0,0,0,2000));
            AdjustFactory.SetSubsessionInterval( new TimeSpan(0,0,0,0,500));

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

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

            // put SDK offline
            activityHandler.SetOfflineMode(true);

            DeviceUtil.Sleep(3000);

            // check if message the disable of the SDK
            Assert.Info("Pausing package and attribution handler to put in offline mode");

            // test init values
            InitTests();

            // test first session start
            CheckFirstSession(paused: true);

            // test end session logs
            CheckEndSession();

            // disable the SDK
            activityHandler.SetEnabled(false);

            // check that it is disabled
            Assert.IsFalse(activityHandler.IsEnabled());

            DeviceUtil.Sleep(1000);

            // writing activity state after disabling
            Assert.Debug("Wrote Activity state: ec:0 sc:1 ssc:1");

            // check if message the disable of the SDK
            Assert.Info("Pausing package and attribution handler to disable the SDK");

            DeviceUtil.Sleep(1000);

            // test end session logs
            CheckEndSession(updateActivityState: false);

            // put SDK back online
            activityHandler.SetOfflineMode(false);

            Assert.Info("Package and attribution handler remain paused because the SDK is disabled");

            DeviceUtil.Sleep(1000);

            // test the update status, still paused
            Assert.NotTest("AttributionHandler PauseSending");
            Assert.NotTest("PackageHandler PauseSending");

            DeviceUtil.Sleep(3000);

            // try to do activities while SDK disabled
            activityHandler.TrackSubsessionStart();
            activityHandler.TrackEvent(new AdjustEvent("event1"));

            DeviceUtil.Sleep(1000);

            // check that timer was not executed
            CheckTimerIsFired(false);

            // check that it did not wrote activity state from new session or subsession
            Assert.NotDebug("Wrote Activity state: ec:0 sc:2");

            // check that it did not add any package
            Assert.NotTest("PackageHandler AddPackage");

            // enable the SDK again
            activityHandler.SetEnabled(true);

            // check that is enabled
            Assert.IsTrue(activityHandler.IsEnabled());

            DeviceUtil.Sleep(1000);

            // test that is not paused anymore
            CheckNewSession(paused: false, sessionCount: 2);
        }
示例#19
0
 public void Init(AdjustConfig adjustConfig, DeviceUtil deviceUtil)
 {
     MockLogger.Test("{0} Init", prefix);
 }
示例#20
0
        public void TestOpenUrl()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: LogLevel.Assert);

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

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

            DeviceUtil.Sleep(3000);

            // test init values
            InitTests(environment: "sandbox", logLevel: "Assert");

            // test first session start
            CheckFirstSession();

            var attributions = new Uri("AdjustTests://example.com/path/inApp?adjust_tracker=trackerValue&other=stuff&adjust_campaign=campaignValue&adjust_adgroup=adgroupValue&adjust_creative=creativeValue");
            var extraParams = new Uri("AdjustTests://example.com/path/inApp?adjust_foo=bar&other=stuff&adjust_key=value");
            var mixed = new Uri("AdjustTests://example.com/path/inApp?adjust_foo=bar&other=stuff&adjust_campaign=campaignValue&adjust_adgroup=adgroupValue&adjust_creative=creativeValue");
            var emptyQueryString = new Uri("AdjustTests://");
            Uri nullUri = null;
            var single = new Uri("AdjustTests://example.com/path/inApp?adjust_foo");
            var prefix = new Uri("AdjustTests://example.com/path/inApp?adjust_=bar");
            var incomplete = new Uri("AdjustTests://example.com/path/inApp?adjust_foo=");

            activityHandler.OpenUrl(attributions);
            activityHandler.OpenUrl(extraParams);
            activityHandler.OpenUrl(mixed);
            activityHandler.OpenUrl(emptyQueryString);
            activityHandler.OpenUrl(nullUri);
            activityHandler.OpenUrl(single);
            activityHandler.OpenUrl(prefix);
            activityHandler.OpenUrl(incomplete);

            DeviceUtil.Sleep(1000);

            // three click packages: attributions, extraParams and mixed
            for (int i = 3; i > 0; i--)
            {
                Assert.Test("PackageHandler AddPackage");
            }

            // checking the default values of the first session package
            // 1 session + 3 click
            Assert.AreEqual(4, MockPackageHandler.PackageQueue.Count);

            // get the click package
            ActivityPackage attributionClickPackage = MockPackageHandler.PackageQueue[1];

            // create activity package test
            TestActivityPackage testAttributionClickPackage = new TestActivityPackage(attributionClickPackage)
            {
                Attribution = new AdjustAttribution
                {
                    TrackerName = "trackerValue",
                    Campaign = "campaignValue",
                    Adgroup = "adgroupValue",
                    Creative = "creativeValue",
                },
            };

            // test the first deeplink
            testAttributionClickPackage.TestClickPackage(source: "deeplink");

            // get the click package
            ActivityPackage extraParamsClickPackage = MockPackageHandler.PackageQueue[2];

            // create activity package test
            TestActivityPackage testExtraParamsClickPackage = new TestActivityPackage(extraParamsClickPackage)
            {
                DeepLinkParameters = "{\"key\":\"value\",\"foo\":\"bar\"}",
            };

            // test the second deeplink
            testExtraParamsClickPackage.TestClickPackage(source: "deeplink");

            // get the click package
            ActivityPackage mixedClickPackage = MockPackageHandler.PackageQueue[3];

            // create activity package test
            TestActivityPackage testMixedClickPackage = new TestActivityPackage(mixedClickPackage)
            {
                Attribution = new AdjustAttribution
                {
                    Campaign = "campaignValue",
                    Adgroup = "adgroupValue",
                    Creative = "creativeValue",
                },
                DeepLinkParameters = "{\"foo\":\"bar\"}",
            };

            // test the third deeplink
            testMixedClickPackage.TestClickPackage(source: "deeplink");
        }
示例#21
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            Adjust.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
            logLevel: LogLevel.Verbose);

            // configure Adjust
            var config = new AdjustConfig("{YourAppToken}", AdjustConfig.EnvironmentSandbox);

            // enable event buffering
            //config.EventBufferingEnabled = true;

            // set default tracker
            //config.DefaultTracker = "{YourDefaultTracker}";

            // set attribution delegate
            config.AttributionChanged = (attribution) =>
                System.Diagnostics.Debug.WriteLine("attribution: " + attribution);

            Adjust.ApplicationLaunching(config);

            // put the SDK in offline mode
            //Adjust.SetOfflineMode(offlineMode: true);

            // disable the SDK
            //Adjust.SetEnabled(enabled: false);
            #if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
            #endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
示例#22
0
        public void TestTimer()
        {
            LogConfig.SetupLogging(logDelegate: msg => System.Diagnostics.Debug.WriteLine(msg),
                logLevel: null);

            AdjustFactory.SetTimerInterval(new TimeSpan(0,0,0,0,4000));
            AdjustFactory.SetTimerStart(new TimeSpan(0,0,0,0,0));

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

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

            DeviceUtil.Sleep(2000);

            // test init values
            InitTests();

            // test first session start
            CheckFirstSession();

            // wait enough to fire the first cycle
            DeviceUtil.Sleep(4000);
            CheckTimerIsFired(true);

            // end subsession to stop timer
            activityHandler.TrackSubsessionEnd();

            // wait enough for a new cycle
            DeviceUtil.Sleep(6000);

            activityHandler.TrackSubsessionStart();

            DeviceUtil.Sleep(1000);

            CheckTimerIsFired(false);
        }