Ejemplo n.º 1
0
        public void TrackEvent(WoopraEvent woopraEvent)
        {
            if (string.IsNullOrWhiteSpace(Domain))
                throw new NullReferenceException("WoopraTracker.Domain property must be set before any call to WoopraTracker.TrackEvent");

            if (Visitor == null)
                throw new NullReferenceException("WoopraTracker.Visitor property must be set before any call to WoopraTracker.TrackEvent");

            var timeoutMs = IdleTimeout.TotalMilliseconds;
            var builder = new StringBuilder($"{EventEndpoint}?app={_platformString}&host={Domain}&cookie={Visitor.Cookie}&response=json&timeout={timeoutMs}");
            if (!string.IsNullOrWhiteSpace(Referer))
                builder.Append($"&referer={Referer}");

            AppendParameters(builder, Properties, "ce_");
            AppendParameters(builder, Visitor.Properties, "cv_");

            foreach (var prop in woopraEvent.Properties)
            {
                var key = prop.Key;
                if (key.StartsWith("~"))
                    key = key.Substring(1);
                else
                    key = $"ce_{key}";
                key = Uri.EscapeUriString(key);
                var value = Uri.EscapeUriString(prop.Value);
                string frag = $"&{key}={value}";
                builder.Append(frag);
            }

            var uri = builder.ToString();
            var request = HttpWebRequest.CreateHttp(uri);
            request.BeginGetResponse(ar => request.EndGetResponse(ar), null);
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            playBarButtonItem.Clicked += (object sender, EventArgs e) =>
                {
                    var domain = domainTextField.Text?.Trim();
                    var email = emailTextField.Text?.Trim();
                    var path = pathTextField.Text?.Trim();

                    if (string.IsNullOrEmpty(domain) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(path))
                    {
                        ShowAlert("Error", "Check all the fields");
                        return;
                    }

                    try
                    {
                        var visitor = WoopraVisitor.CreateWithEmail(new TouchWoopraCrypto(), email);
                        var device = UIDevice.CurrentDevice;
                        var tracker = new WoopraTracker(visitor, device.Model, $"{device.SystemName} {device.SystemVersion}", "SampleApp", "ios")
                            {
                                Domain = domain
                            };
                        var wEvent = new WoopraEvent("pv");
                        wEvent.Properties.Add("url", path);
                        tracker.TrackEvent(wEvent);

                        ShowAlert("Completed", "");
                    }
                    catch (Exception ex)
                    {
                        ShowAlert(ex.GetType().Name, ex.Message);
                    }
                };
        }