Beispiel #1
0
        public MainPage()
        {
            Location = new YandexMetrica.Location();
            InitializeComponent();

            Loaded   += (sender, args) => YandexMetrica.ReportEvent("Hello!");
            Unloaded += (sender, args) => YandexMetrica.ReportEvent("Bye!");

            LocationButton.Click += (sender, args) => YandexMetricaConfig.SetCustomLocation(Location);
            EventButton.Click    += (sender, args) => YandexMetrica.ReportEvent(EventNameTextBox.Text);
            CrashButton.Click    += (sender, args) => { throw new Exception(); };
            ErrorButton.Click    += (sender, args) =>
            {
                try
                {
                    throw new ArgumentException("Throw exception and catch it");
                }
                catch (Exception exception)
                {
                    YandexMetrica.ReportError(ErrorNameTextBox.Text, exception);
                }
            };

            ResetButton.Click += (sender, args) =>
            {
                YandexMetricaConfig.OfflineMode      = false;
                YandexMetricaConfig.CrashTracking    = true;
                YandexMetricaConfig.LocationTracking = true;
                YandexMetricaConfig.CustomAppVersion = null;
                YandexMetricaConfig.SetCustomLocation(null);
            };

            JsonButton.Click += (sender, args) => YandexMetrica.ReportEvent("abc", JsonData.GetObject());
            JsonButton.Click += (sender, args) => YandexMetrica.ReportEvent("abc", JsonData.GetDictionary());
        }
Beispiel #2
0
        public static YandexMetricaConfig AppMetricaConfig()
        {
            var config = new YandexMetricaConfig(ApiKey());

            config.InstalledAppCollecting = false;

            return(config);
        }
Beispiel #3
0
        public static void Activate(YandexMetricaConfig config)
        {
            YMMYandexMetrica.ActivateWithConfiguration(config.ToIOSAppMetricaConfig());

            YandexMetrica.RegisterImplementation(new YandexMetricaImplementation());
            YandexMetricaAttributeImplementation.Init();
            UpdateConfiguration(config);
        }
Beispiel #4
0
        public static void Activate(Context context, YandexMetricaConfig config, Application app = null)
        {
            Com.Yandex.Metrica.YandexMetrica.Activate(context, config.ToAndroidMetricaConfig());
            EnableActivityAutoTracking(app);

            YandexMetrica.RegisterImplementation(new YandexMetricaImplementation());
            YandexMetricaAttributeImplementation.Init();
            UpdateConfiguration(config);
        }
Beispiel #5
0
        public static Com.Yandex.Metrica.YandexMetricaConfig ToAndroidMetricaConfig(this YandexMetricaConfig self)
        {
            var builder = Com.Yandex.Metrica.YandexMetricaConfig.NewConfigBuilder(self.ApiKey);

            if (self.Location != null)
            {
                builder.WithLocation(self.Location.ToLocation());
            }
            if (self.AppVersion != null)
            {
                builder.WithAppVersion(self.AppVersion);
            }
            if (self.LocationTracking.HasValue)
            {
                builder.WithLocationTracking(self.LocationTracking.Value);
            }
            if (self.SessionTimeout.HasValue)
            {
                builder.WithSessionTimeout(self.SessionTimeout.Value);
            }
            if (self.CrashReporting.HasValue)
            {
                builder.WithCrashReporting(self.CrashReporting.Value);
            }
            if (self.Logs.HasValue && self.Logs.Value)
            {
                builder.WithLogs();
            }
            if (self.InstalledAppCollecting.HasValue)
            {
                builder.WithInstalledAppCollecting(self.InstalledAppCollecting.Value);
            }
            if (self.StatisticsSending.HasValue)
            {
                builder.WithStatisticsSending(self.StatisticsSending.Value);
            }
            if (self.HandleFirstActivationAsUpdate.HasValue)
            {
                builder.HandleFirstActivationAsUpdate(self.HandleFirstActivationAsUpdate.Value);
            }
            if (self.PreloadInfo != null)
            {
                var preloadInfoBuilder = Com.Yandex.Metrica.PreloadInfo.NewBuilder(self.PreloadInfo.TrackingId);
                foreach (var kvp in self.PreloadInfo.AdditionalInfo)
                {
                    preloadInfoBuilder.SetAdditionalParams(kvp.Key, kvp.Value);
                }
                builder.WithPreloadInfo(preloadInfoBuilder.Build());
            }

            // Native crashes are currently not supported
            builder.WithNativeCrashReporting(false);

            return(builder.Build());
        }
Beispiel #6
0
        public static YMMYandexMetricaConfiguration ToIOSAppMetricaConfig(this YandexMetricaConfig self)
        {
            var nativeConfig = new YMMYandexMetricaConfiguration(self.ApiKey);

            if (self.Location != null)
            {
                nativeConfig.Location = self.Location.ToCLLocation();
            }
            if (self.AppVersion != null)
            {
                nativeConfig.AppVersion = self.AppVersion;
            }
            if (self.LocationTracking.HasValue)
            {
                nativeConfig.LocationTracking = self.LocationTracking.Value;
            }
            if (self.SessionTimeout.HasValue)
            {
                nativeConfig.SessionTimeout = (nuint)self.SessionTimeout.Value;
            }
            if (self.CrashReporting.HasValue)
            {
                nativeConfig.CrashReporting = self.CrashReporting.Value;
            }
            if (self.Logs.HasValue)
            {
                nativeConfig.Logs = self.Logs.Value;
            }
            if (self.StatisticsSending.HasValue)
            {
                nativeConfig.StatisticsSending = self.StatisticsSending.Value;
            }
            if (self.HandleFirstActivationAsUpdate.HasValue)
            {
                nativeConfig.HandleFirstActivationAsUpdate = self.HandleFirstActivationAsUpdate.Value;
            }
            if (self.PreloadInfo != null)
            {
                var preloadInfo = new YMMYandexMetricaPreloadInfo(self.PreloadInfo.TrackingId);
                foreach (var kvp in self.PreloadInfo.AdditionalInfo)
                {
                    preloadInfo.SetAdditionalInfo(kvp.Value, kvp.Key);
                }
                nativeConfig.PreloadInfo = preloadInfo;
            }

            return(nativeConfig);
        }