public MATParameters Copy()
        {
            MATParameters copy = new MATParameters();

            copy.advertiserId  = this.advertiserId;
            copy.advertiserKey = this.advertiserKey;
            copy.matRequest    = this.matRequest; //Make this a hard copy

            copy.Age               = this.Age;
            copy.AllowDuplicates   = this.AllowDuplicates;
            copy.Altitude          = this.Altitude;
            copy.AppAdTracking     = this.AppAdTracking;
            copy.AppName           = this.AppName;
            copy.AppVersion        = this.AppVersion;
            copy.DebugMode         = this.DebugMode;
            copy.DeviceBrand       = this.DeviceBrand;
            copy.DeviceCarrier     = this.DeviceCarrier;
            copy.DeviceModel       = this.DeviceModel;
            copy.DeviceUniqueId    = this.DeviceUniqueId;
            copy.DeviceScreenSize  = this.DeviceScreenSize;
            copy.EventContentType  = this.EventContentType;
            copy.EventContentId    = this.EventContentId;
            copy.EventLevel        = this.EventLevel;
            copy.EventQuantity     = this.EventQuantity;
            copy.EventSearchString = this.EventSearchString;
            copy.EventRating       = this.EventRating;
            copy.EventDate1        = this.EventDate1;
            copy.EventDate2        = this.EventDate2;
            copy.EventAttribute1   = this.EventAttribute1;
            copy.EventAttribute2   = this.EventAttribute2;
            copy.EventAttribute3   = this.EventAttribute3;
            copy.EventAttribute4   = this.EventAttribute4;
            copy.EventAttribute5   = this.EventAttribute5;
            copy.ExistingUser      = this.ExistingUser;
            copy.FacebookUserId    = this.FacebookUserId;
            copy.Gender            = this.Gender;
            copy.GoogleUserId      = this.GoogleUserId;
            copy.IsPayingUser      = this.IsPayingUser;
            copy.LastOpenLogId     = this.LastOpenLogId;
            copy.Latitude          = this.Latitude;
            copy.Longitude         = this.Longitude;
            copy.MatId             = this.MatId;
            copy.OpenLogId         = this.OpenLogId;
            copy.OSVersion         = this.OSVersion;
            copy.PackageName       = this.PackageName;
            copy.PhoneNumber       = this.PhoneNumber;
            copy.TwitterUserId     = this.TwitterUserId;
            copy.UserEmail         = this.UserEmail;
            copy.UserEmailMd5      = this.UserEmailMd5;
            copy.UserEmailSha1     = this.UserEmailSha1;
            copy.UserEmailSha256   = this.UserEmailSha256;
            copy.UserId            = this.UserId;
            copy.UserName          = this.UserName;
            copy.UserNameMd5       = this.UserNameMd5;
            copy.UserNameSha1      = this.UserNameSha1;
            copy.UserNameSha256    = this.UserNameSha256;
            copy.WindowsAid        = this.WindowsAid;

            return(copy);
        }
        private void Track(string eventName, double revenue = 0, string currency = null, string refId = null, List <MATEventItem> eventItems = null)
        {
            string action = "conversion";

            // Don't send close events
            if (eventName.Equals("close"))
            {
                return;
            }
            if (eventName.Equals("open") || eventName.Equals("install") || eventName.Equals("update") || eventName.Equals("session"))
            {
                action = "session";
            }

            if (revenue > 0)
            {
                parameters.IsPayingUser = true;
            }

            //Create hard copy of fields before making async tracking request
            MATParameters copy = parameters.Copy();

            eventQueue.ProcessTrackingRequest(action, eventName, revenue, currency, refId, eventItems, copy);

            if (parameters.matResponse != null)
            {
                parameters.matResponse.EnqueuedActionWithRefId(refId);
            }

            parameters.EventContentType  = null;
            parameters.EventContentId    = null;
            parameters.EventLevel        = 0;
            parameters.EventQuantity     = 0;
            parameters.EventSearchString = null;
            parameters.EventRating       = 0.0;
            parameters.EventDate1        = null;
            parameters.EventDate2        = null;
            parameters.EventAttribute1   = null;
            parameters.EventAttribute2   = null;
            parameters.EventAttribute3   = null;
            parameters.EventAttribute4   = null;
            parameters.EventAttribute5   = null;
        }
        private void Track(string eventName, double revenue = 0, string currency = null, string refId = null, List <MATEventItem> eventItems = null)
        {
            string action = "conversion";

            // Don't send close events
            if (eventName.Equals("close"))
            {
                return;
            }
            if (eventName.Equals("open") || eventName.Equals("install") || eventName.Equals("update") || eventName.Equals("session"))
            {
                action = "session";
            }

            if (revenue > 0)
            {
                parameters.IsPayingUser = true;
            }

            //Add to queue and process building operation in separate thread.
            //Copy is required because of async
            MATParameters copy = parameters.Copy();

            eventQueue.ProcessTrackingRequest(action, eventName, revenue, currency, refId, eventItems, copy);

            parameters.EventContentType  = null;
            parameters.EventContentId    = null;
            parameters.EventLevel        = 0;
            parameters.EventQuantity     = 0;
            parameters.EventSearchString = null;
            parameters.EventRating       = 0.0;
            parameters.EventDate1        = null;
            parameters.EventDate2        = null;
            parameters.EventAttribute1   = null;
            parameters.EventAttribute2   = null;
            parameters.EventAttribute3   = null;
            parameters.EventAttribute4   = null;
            parameters.EventAttribute5   = null;
        }
예제 #4
0
        internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List<MATEventItem> eventItems, MATParameters copy)
        {
            lock (syncLock)
            {
                if (queueThread == null || !queueThread.IsAlive)
                {
                    queueThread = new Thread(delegate() //Start on separate thread to avoid slowdown
                    {
                        DumpQueue(); //Clear anything from the last dump
                        List<MATUrlBuilder.URLInfo> eventQueue;
                        // Get existing event queue or create new one
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(MATConstants.SETTINGS_MATEVENTQUEUE_KEY) &&
                            IsolatedStorageSettings.ApplicationSettings[MATConstants.SETTINGS_MATEVENTQUEUE_KEY].GetType() == typeof(List<MATUrlBuilder.URLInfo>))
                        {
                            eventQueue = (List<MATUrlBuilder.URLInfo>)IsolatedStorageSettings.ApplicationSettings[MATConstants.SETTINGS_MATEVENTQUEUE_KEY];
                        }
                        else // No existing queue, create
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove(MATConstants.SETTINGS_MATEVENTQUEUE_KEY);
                            eventQueue = new List<MATUrlBuilder.URLInfo>();
                        }

                        MATUrlBuilder.URLInfo url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, copy);
                        eventQueue.Add(url);
                        SaveLocalSetting(MATConstants.SETTINGS_MATEVENTQUEUE_KEY, eventQueue);
                        
                        if (parameters.matResponse != null)
                            parameters.matResponse.EnqueuedActionWithRefId(refId); 
                        
                        DumpQueue();
                    });
                    queueThread.Start();
                }
            }
        }
예제 #5
0
 internal MATEventQueue(MATParameters parameters)
 {
     syncLock = new object();
     this.parameters = parameters;
 }
        // Add a url to event queue to send later
        internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, MATParameters paramCopy)
        {
            Debug.WriteLine("Processing tracking request");
            lock (syncLock)
            {
                Task.Factory.StartNew(() =>
                {
                    DumpQueue();
                    string url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, paramCopy);
                    // Convert event items to correct JSON
                    var jsonData = JsonConvert.SerializeObject(new { data = eventItems }, Formatting.None);

                    AddToQueue(url, jsonData, 0);
                    DumpQueue();
                });
            }
        }
 protected internal MATEventQueue(MATParameters parameters)
 {
     this.parameters = parameters;
     syncLock        = new Object();
 }
예제 #8
0
 public MATEventQueueWrapper(MATParameters parameters)
 {
     this.parameters = parameters;
 }
예제 #9
0
 internal MATUrlRequester(MATParameters parameters, MATEventQueue eventQueue)
 {
     this.parameters = parameters;
     this.eventQueue = eventQueue;
 }
예제 #10
0
        internal static URLInfo BuildUrl(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, MATParameters parameters)
        {
            StringBuilder url = new StringBuilder("https://");

            url.Append(Uri.EscapeUriString(parameters.advertiserId)).Append(".");

            if (parameters.DebugMode)
            {
                url.Append("debug.");
            }
            url.Append(MATConstants.DOMAIN).Append("/serve?sdk=").Append(MATConstants.SDK_TYPE).Append("&ver=").Append(MATConstants.SDK_VERSION);
            url.Append("&advertiser_id=").Append(Uri.EscapeUriString(parameters.advertiserId));
            url.Append("&mat_id=").Append(Uri.EscapeUriString(parameters.MatId));
            url.Append("&action=").Append(Uri.EscapeUriString(action));
            url.Append("&package_name=").Append(Uri.EscapeUriString(parameters.PackageName));
            url.Append("&transaction_id=").Append(Guid.NewGuid().ToString().ToUpper());
            // Append event name/ID for events
            if (action.Equals("conversion"))
            {
                long value;
                if (long.TryParse(eventName, out value))
                {
                    url.Append("&site_event_id=").Append(eventName);
                }
                else
                {
                    url.Append("&site_event_name=").Append(Uri.EscapeUriString(eventName));
                }
            }

            // Append open log id
            if (parameters.OpenLogId != null)
            {
                url.Append("&open_log_id=").Append(Uri.EscapeUriString(parameters.OpenLogId));
            }
            if (parameters.LastOpenLogId != null)
            {
                url.Append("&last_open_log_id=").Append(Uri.EscapeUriString(parameters.LastOpenLogId));
            }

            if (parameters.AllowDuplicates)
            {
                url.Append("&skip_dup=1");
            }
            if (parameters.DebugMode)
            {
                url.Append("&debug=1");
            }
            if (parameters.ExistingUser)
            {
                url.Append("&existing_user=1");
            }

            // Construct encrypted data params and append to url
            StringBuilder data = new StringBuilder();
            // Add UNIX timestamp as system date
            long timestamp = UnixTimestamp();

            data.Append("&system_date=").Append(timestamp.ToString());

            data.Append("&app_name=").Append(Uri.EscapeUriString(parameters.AppName));
            data.Append("&app_version=").Append(Uri.EscapeUriString(parameters.AppVersion));
            data.Append("&device_brand=").Append(Uri.EscapeUriString(parameters.DeviceBrand));
            data.Append("&device_model=").Append(Uri.EscapeUriString(parameters.DeviceModel));
            data.Append("&device_carrier=").Append(Uri.EscapeUriString(parameters.DeviceCarrier));
            data.Append("&device_screen_size=").Append(Uri.EscapeUriString(parameters.DeviceScreenSize));
            data.Append("&os_id=").Append(Uri.EscapeUriString(parameters.DeviceUniqueId));
            data.Append("&os_version=").Append(Uri.EscapeUriString(parameters.OSVersion));


            if (parameters.AppAdTracking)
            {
                data.Append("&app_ad_tracking=1");
            }
            else
            {
                data.Append("&app_ad_tracking=0");
            }

            if (revenue > 0)
            {
                data.Append("&revenue=").Append(Uri.EscapeUriString(revenue.ToString()));
            }
            if (currency != null)
            {
                data.Append("&currency_code=").Append(Uri.EscapeUriString(currency));
            }
            if (refId != null)
            {
                data.Append("&advertiser_ref_id=").Append(Uri.EscapeUriString(refId));
            }

            if (parameters.Age > 0)
            {
                data.Append("&age=").Append(Uri.EscapeUriString(parameters.Age.ToString()));
            }
            data.Append("&altitude=").Append(Uri.EscapeUriString(parameters.Altitude.ToString()));
            if (parameters.EventContentType != null)
            {
                data.Append("&content_type=").Append(Uri.EscapeUriString(parameters.EventContentType));
            }
            if (parameters.EventContentId != null)
            {
                data.Append("&content_id=").Append(Uri.EscapeUriString(parameters.EventContentId));
            }
            data.Append("&level=").Append(parameters.EventLevel.ToString());
            data.Append("&quantity=").Append(parameters.EventQuantity.ToString());
            if (parameters.EventSearchString != null)
            {
                data.Append("&search_string=").Append(Uri.EscapeUriString(parameters.EventSearchString));
            }
            data.Append("&rating=").Append(Uri.EscapeUriString(parameters.EventRating.ToString()));
            if (parameters.EventDate1 != null)
            {
                data.Append("&date1=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate1).ToString()));
            }
            if (parameters.EventDate2 != null)
            {
                data.Append("&date2=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate2).ToString()));
            }
            if (parameters.EventAttribute1 != null)
            {
                data.Append("&attribute_sub1=").Append(Uri.EscapeUriString(parameters.EventAttribute1));
            }
            if (parameters.EventAttribute2 != null)
            {
                data.Append("&attribute_sub2=").Append(Uri.EscapeUriString(parameters.EventAttribute2));
            }
            if (parameters.EventAttribute3 != null)
            {
                data.Append("&attribute_sub3=").Append(Uri.EscapeUriString(parameters.EventAttribute3));
            }
            if (parameters.EventAttribute4 != null)
            {
                data.Append("&attribute_sub4=").Append(Uri.EscapeUriString(parameters.EventAttribute4));
            }
            if (parameters.EventAttribute5 != null)
            {
                data.Append("&attribute_sub5=").Append(Uri.EscapeUriString(parameters.EventAttribute5));
            }
            if (parameters.FacebookUserId != null)
            {
                data.Append("&facebook_user_id=").Append(Uri.EscapeUriString(parameters.FacebookUserId));
            }
            if (parameters.Gender != MATGender.NONE)
            {
                data.Append("&gender=").Append(Uri.EscapeUriString(parameters.Gender.ToString()));
            }
            if (parameters.GoogleUserId != null)
            {
                data.Append("&google_user_id=").Append(Uri.EscapeUriString(parameters.GoogleUserId));
            }
            if (parameters.IsPayingUser != false)
            {
                data.Append("&is_paying_user=1");
            }
            if (parameters.Latitude != 0)
            {
                data.Append("&latitude=").Append(Uri.EscapeUriString(parameters.Latitude.ToString()));
            }
            if (parameters.Longitude != 0)
            {
                data.Append("&longitude=").Append(Uri.EscapeUriString(parameters.Longitude.ToString()));
            }
            if (parameters.PhoneNumber != null)
            {
                data.Append("&user_phone_md5=").Append(Uri.EscapeUriString(parameters.PhoneNumberMd5));
                data.Append("&user_phone_sha1=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha1));
                data.Append("&user_phone_sha256=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha256));
            }
            if (parameters.TwitterUserId != null)
            {
                data.Append("&twitter_user_id=").Append(Uri.EscapeUriString(parameters.TwitterUserId));
            }
            if (parameters.UserEmail != null)
            {
                data.Append("&user_email_md5=").Append(Uri.EscapeUriString(parameters.UserEmailMd5));
                data.Append("&user_email_sha1=").Append(Uri.EscapeUriString(parameters.UserEmailSha1));
                data.Append("&user_email_sha256=").Append(Uri.EscapeUriString(parameters.UserEmailSha256));
            }
            if (parameters.UserId != null)
            {
                data.Append("&user_id=").Append(Uri.EscapeUriString(parameters.UserId));
            }
            if (parameters.UserName != null)
            {
                data.Append("&user_name_md5=").Append(Uri.EscapeUriString(parameters.UserNameMd5));
                data.Append("&user_name_sha1=").Append(Uri.EscapeUriString(parameters.UserNameSha1));
                data.Append("&user_name_sha256=").Append(Uri.EscapeUriString(parameters.UserNameSha256));
            }
            if (parameters.WindowsAid != null)
            {
                data.Append("&windows_aid=").Append(Uri.EscapeUriString(parameters.WindowsAid));
            }

            // Add event items to url as json string
            if (eventItems != null)
            {
                data.Append("&site_event_items=").Append(Uri.EscapeUriString(JsonConvert.SerializeObject(eventItems)));
            }

            if (parameters.matRequest != null)
            {
                parameters.matRequest.ParamsToBeEncrypted(data.ToString());
            }

            // Encrypt data string as byte array

            /*byte[] encryptedDataBytes = urlEncrypter.Encrypt(data.ToString());
             *
             * String decrypted = urlEncrypter.Decrypt(encryptedDataBytes);
             *
             * // Convert byte[] to hex string to append to url
             * string dataStr = BitConverter.ToString(encryptedDataBytes).Replace("-", string.Empty);*/

            //string dataStr = Encryption.ByteArrayToString(encryptedDataBytes);

            url.Append("&data=").Append(data.ToString());

            url.Append("&response_format=json");

            if (parameters.matRequest != null)
            {
                parameters.matRequest.ConstructedRequest(url.ToString());
            }

            URLInfo newURL = new URLInfo();

            newURL.url          = url.ToString();
            newURL.retryAttempt = 0;

            return(newURL);
        }
예제 #11
0
        public MATParameters Copy()
        {
            MATParameters copy = new MATParameters();

            copy.advertiserId = this.advertiserId;
            copy.advertiserKey = this.advertiserKey;
            copy.matRequest = this.matRequest; //Make this a hard copy

            copy.Age = this.Age;
            copy.AllowDuplicates = this.AllowDuplicates;
            copy.Altitude = this.Altitude;
            copy.AppAdTracking = this.AppAdTracking;
            copy.AppName = this.AppName;
            copy.AppVersion = this.AppVersion;
            copy.DebugMode = this.DebugMode;
            copy.DeviceBrand = this.DeviceBrand;
            copy.DeviceCarrier = this.DeviceCarrier;
            copy.DeviceModel = this.DeviceModel;
            copy.DeviceUniqueId = this.DeviceUniqueId;
            copy.DeviceScreenSize = this.DeviceScreenSize;
            copy.EventContentType = this.EventContentType;
            copy.EventContentId = this.EventContentId;
            copy.EventLevel = this.EventLevel;
            copy.EventQuantity = this.EventQuantity;
            copy.EventSearchString = this.EventSearchString;
            copy.EventRating = this.EventRating;
            copy.EventDate1 = this.EventDate1;
            copy.EventDate2 = this.EventDate2;
            copy.EventAttribute1 = this.EventAttribute1;
            copy.EventAttribute2 = this.EventAttribute2;
            copy.EventAttribute3 = this.EventAttribute3;
            copy.EventAttribute4 = this.EventAttribute4;
            copy.EventAttribute5 = this.EventAttribute5;
            copy.ExistingUser = this.ExistingUser;
            copy.FacebookUserId = this.FacebookUserId;
            copy.Gender = this.Gender;
            copy.GoogleUserId = this.GoogleUserId;
            copy.IsPayingUser = this.IsPayingUser;
            copy.LastOpenLogId = this.LastOpenLogId;
            copy.Latitude = this.Latitude;
            copy.Longitude = this.Longitude;
            copy.MatId = this.MatId;
            copy.OpenLogId = this.OpenLogId;
            copy.OSVersion = this.OSVersion;
            copy.PackageName = this.PackageName;
            copy.PhoneNumber = this.PhoneNumber;
            copy.TwitterUserId = this.TwitterUserId;
            copy.UserEmail = this.UserEmail;
            copy.UserEmailMd5 = this.UserEmailMd5;
            copy.UserEmailSha1 = this.UserEmailSha1;
            copy.UserEmailSha256 = this.UserEmailSha256;
            copy.UserId = this.UserId;
            copy.UserName = this.UserName;
            copy.UserNameMd5 = this.UserNameMd5;
            copy.UserNameSha1 = this.UserNameSha1;
            copy.UserNameSha256 = this.UserNameSha256;
            copy.WindowsAid = this.WindowsAid;

            return copy;
        }
 internal MATEventQueue(MATParameters parameters)
 {
     syncLock        = new object();
     this.parameters = parameters;
 }
        internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, MATParameters copy)
        {
            lock (syncLock)
            {
                if (queueThread == null || !queueThread.IsAlive)
                {
                    queueThread = new Thread(delegate() //Start on separate thread to avoid slowdown
                    {
                        DumpQueue();                    //Clear anything from the last dump
                        List <MATUrlBuilder.URLInfo> eventQueue;
                        // Get existing event queue or create new one
                        if (IsolatedStorageSettings.ApplicationSettings.Contains(MATConstants.SETTINGS_MATEVENTQUEUE_KEY) &&
                            IsolatedStorageSettings.ApplicationSettings[MATConstants.SETTINGS_MATEVENTQUEUE_KEY].GetType() == typeof(List <MATUrlBuilder.URLInfo>))
                        {
                            eventQueue = (List <MATUrlBuilder.URLInfo>)IsolatedStorageSettings.ApplicationSettings[MATConstants.SETTINGS_MATEVENTQUEUE_KEY];
                        }
                        else // No existing queue, create
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove(MATConstants.SETTINGS_MATEVENTQUEUE_KEY);
                            eventQueue = new List <MATUrlBuilder.URLInfo>();
                        }

                        MATUrlBuilder.URLInfo url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, copy);
                        eventQueue.Add(url);
                        SaveLocalSetting(MATConstants.SETTINGS_MATEVENTQUEUE_KEY, eventQueue);

                        if (parameters.matResponse != null)
                        {
                            parameters.matResponse.EnqueuedActionWithRefId(refId);
                        }

                        DumpQueue();
                    });
                    queueThread.Start();
                }
            }
        }
예제 #14
0
        //TODO: Look into using JSON rather than strings
        public static string BuildUrl(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, MATParameters parameters)
        {
            StringBuilder url = new StringBuilder("https://");

            url.Append(Uri.EscapeUriString(parameters.advertiserId)).Append(".");

            if (parameters.DebugMode)
            {
                url.Append("debug.");
            }
            url.Append(MATConstants.DOMAIN).Append("/serve?sdk=").Append(MATConstants.SDK_TYPE).Append("&ver=").Append(MATConstants.SDK_VERSION);
            url.Append("&advertiser_id=").Append(Uri.EscapeUriString(parameters.advertiserId));
            url.Append("&mat_id=").Append(Uri.EscapeUriString(parameters.MatId));
            url.Append("&action=").Append(Uri.EscapeUriString(action));
            url.Append("&package_name=").Append(Uri.EscapeUriString(parameters.PackageName));
            url.Append("&transaction_id=").Append(Guid.NewGuid().ToString().ToUpper());
            // Append event name/ID for events
            if (action.Equals("conversion"))
            {
                long value;
                if (long.TryParse(eventName, out value))
                {
                    url.Append("&site_event_id=").Append(eventName);
                }
                else
                {
                    url.Append("&site_event_name=").Append(Uri.EscapeUriString(eventName));
                }
            }

            // Append open log id
            if (parameters.OpenLogId != null)
            {
                url.Append("&open_log_id=").Append(Uri.EscapeUriString(parameters.OpenLogId));
            }
            if (parameters.LastOpenLogId != null)
            {
                url.Append("&last_open_log_id=").Append(Uri.EscapeUriString(parameters.LastOpenLogId));
            }

            if (parameters.AllowDuplicates)
            {
                url.Append("&skip_dup=1");
            }
            if (parameters.DebugMode)
            {
                url.Append("&debug=1");
            }
            if (parameters.ExistingUser)
            {
                url.Append("&existing_user=1");
            }

            // Construct encrypted data params and append to url
            StringBuilder data = new StringBuilder();
            // Add UNIX timestamp as system date
            long timestamp = UnixTimestamp();

            data.Append("&system_date=").Append(timestamp.ToString());

            data.Append("&windows_aid=").Append(Uri.EscapeUriString(parameters.WindowsAid));
            data.Append("&app_name=").Append(Uri.EscapeUriString(parameters.AppName));
            data.Append("&app_version=").Append(Uri.EscapeUriString(parameters.AppVersion));
            data.Append("&os_id=").Append(Uri.EscapeUriString(parameters.ASHWID));
            if (parameters.UserAgent != null)
            {
                data.Append("&user_agent=").Append(Uri.EscapeUriString(parameters.UserAgent));
            }
            if (parameters.AppAdTracking)
            {
                data.Append("&app_ad_tracking=1");
            }
            else
            {
                data.Append("&app_ad_tracking=0");
            }

            if (revenue > 0)
            {
                data.Append("&revenue=").Append(Uri.EscapeUriString(revenue.ToString(parameters.culture)));
            }
            if (currency != null)
            {
                data.Append("&currency_code=").Append(Uri.EscapeUriString(currency));
            }
            if (refId != null)
            {
                data.Append("&advertiser_ref_id=").Append(Uri.EscapeUriString(refId));
            }

            if (parameters.Age > 0)
            {
                data.Append("&age=").Append(Uri.EscapeUriString(parameters.Age.ToString(parameters.culture)));
            }
            data.Append("&altitude=").Append(Uri.EscapeUriString(parameters.Altitude.ToString()));
            if (parameters.EventContentType != null)
            {
                data.Append("&content_type=").Append(Uri.EscapeUriString(parameters.EventContentType));
            }
            if (parameters.EventContentId != null)
            {
                data.Append("&content_id=").Append(Uri.EscapeUriString(parameters.EventContentId));
            }
            data.Append("&level=").Append(parameters.EventLevel.ToString());
            data.Append("&quantity=").Append(parameters.EventQuantity.ToString());
            if (parameters.EventSearchString != null)
            {
                data.Append("&search_string=").Append(Uri.EscapeUriString(parameters.EventSearchString));
            }
            data.Append("&rating=").Append(Uri.EscapeUriString(parameters.EventRating.ToString()));
            if (parameters.EventDate1 != null)
            {
                data.Append("&date1=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate1).ToString()));
            }
            if (parameters.EventDate2 != null)
            {
                data.Append("&date2=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate2).ToString()));
            }
            if (parameters.EventAttribute1 != null)
            {
                data.Append("&attribute_sub1=").Append(Uri.EscapeUriString(parameters.EventAttribute1));
            }
            if (parameters.EventAttribute2 != null)
            {
                data.Append("&attribute_sub2=").Append(Uri.EscapeUriString(parameters.EventAttribute2));
            }
            if (parameters.EventAttribute3 != null)
            {
                data.Append("&attribute_sub3=").Append(Uri.EscapeUriString(parameters.EventAttribute3));
            }
            if (parameters.EventAttribute4 != null)
            {
                data.Append("&attribute_sub4=").Append(Uri.EscapeUriString(parameters.EventAttribute4));
            }
            if (parameters.EventAttribute5 != null)
            {
                data.Append("&attribute_sub5=").Append(Uri.EscapeUriString(parameters.EventAttribute5));
            }
            if (parameters.DeviceBrand != null)
            {
                data.Append("&device_brand=").Append(Uri.EscapeUriString(parameters.DeviceBrand));
            }
            if (parameters.DeviceModel != null)
            {
                data.Append("&device_model=").Append(Uri.EscapeUriString(parameters.DeviceModel));
            }
            if (parameters.DeviceType != null)
            {
                data.Append("&device_type=").Append(Uri.EscapeUriString(parameters.DeviceType));
            }
            if (parameters.FacebookUserId != null)
            {
                data.Append("&facebook_user_id=").Append(Uri.EscapeUriString(parameters.FacebookUserId));
            }
            if (parameters.Gender != MATGender.NONE)
            {
                data.Append("&gender=").Append(Uri.EscapeUriString(((int)parameters.Gender).ToString(parameters.culture)));
            }
            if (parameters.GoogleUserId != null)
            {
                data.Append("&google_user_id=").Append(Uri.EscapeUriString(parameters.GoogleUserId));
            }
            if (parameters.IsPayingUser != false)
            {
                data.Append("&is_paying_user=1");
            }
            if (parameters.Latitude != 0)
            {
                data.Append("&latitude=").Append(Uri.EscapeUriString(parameters.Latitude.ToString(parameters.culture)));
            }
            if (parameters.Longitude != 0)
            {
                data.Append("&longitude=").Append(Uri.EscapeUriString(parameters.Longitude.ToString(parameters.culture)));
            }
            if (parameters.PhoneNumber != null)
            {
                data.Append("&user_phone_md5=").Append(Uri.EscapeUriString(parameters.PhoneNumberMd5));
                data.Append("&user_phone_sha1=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha1));
                data.Append("&user_phone_sha256=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha256));
            }
            if (parameters.TwitterUserId != null)
            {
                data.Append("&twitter_user_id=").Append(Uri.EscapeUriString(parameters.TwitterUserId));
            }
            if (parameters.UserEmail != null)
            {
                data.Append("&user_email_md5=").Append(Uri.EscapeUriString(parameters.UserEmailMd5));
                data.Append("&user_email_sha1=").Append(Uri.EscapeUriString(parameters.UserEmailSha1));
                data.Append("&user_email_sha256=").Append(Uri.EscapeUriString(parameters.UserEmailSha256));
            }
            if (parameters.UserId != null)
            {
                data.Append("&user_id=").Append(Uri.EscapeUriString(parameters.UserId));
            }
            if (parameters.UserName != null)
            {
                data.Append("&user_name_md5=").Append(Uri.EscapeUriString(parameters.UserNameMd5));
                data.Append("&user_name_sha1=").Append(Uri.EscapeUriString(parameters.UserNameSha1));
                data.Append("&user_name_sha256=").Append(Uri.EscapeUriString(parameters.UserNameSha256));
            }

            if (parameters.matRequest != null)
            {
                parameters.matRequest.ParamsToBeEncrypted(data.ToString());
            }

            // Add data string
            url.Append("&data=").Append(data.ToString());

            url.Append("&response_format=json");

            if (parameters.matRequest != null)
            {
                parameters.matRequest.ConstructedRequest(url.ToString());
            }

            return(url.ToString());
        }
예제 #15
0
 // Add a url to event queue to send later
 internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List <MATEventItem> eventItems, MATParameters paramCopy)
 {
     Debug.WriteLine("Processing tracking request");
     lock (syncLock)
     {
         Task.Factory.StartNew(() =>
         {
             DumpQueue();
             string url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, paramCopy);
             AddToQueue(url, 0);
             DumpQueue();
         });
     }
 }
예제 #16
0
        //TODO: Look into using JSON rather than strings
        public static string BuildUrl(string action, string eventName, double revenue, string currency, string refId, List<MATEventItem> eventItems, MATParameters parameters)
        {
            StringBuilder url = new StringBuilder("https://");
            url.Append(Uri.EscapeUriString(parameters.advertiserId)).Append(".");

            if (parameters.DebugMode)
                url.Append("debug.");
            url.Append(MATConstants.DOMAIN).Append("/serve?sdk=").Append(MATConstants.SDK_TYPE).Append("&ver=").Append(MATConstants.SDK_VERSION);
            url.Append("&advertiser_id=").Append(Uri.EscapeUriString(parameters.advertiserId));
            url.Append("&mat_id=").Append(Uri.EscapeUriString(parameters.MatId));
            url.Append("&action=").Append(Uri.EscapeUriString(action));
            url.Append("&package_name=").Append(Uri.EscapeUriString(parameters.PackageName));
            url.Append("&transaction_id=").Append(Guid.NewGuid().ToString().ToUpper());
            // Append event name/ID for events
            if (action.Equals("conversion"))
            {
                long value;
                if (long.TryParse(eventName, out value))
                    url.Append("&site_event_id=").Append(eventName);
                else
                    url.Append("&site_event_name=").Append(Uri.EscapeUriString(eventName));
            }

            // Append open log id
            if (parameters.OpenLogId != null)
                url.Append("&open_log_id=").Append(Uri.EscapeUriString(parameters.OpenLogId));
            if (parameters.LastOpenLogId != null)
                url.Append("&last_open_log_id=").Append(Uri.EscapeUriString(parameters.LastOpenLogId));

            if (parameters.AllowDuplicates)
                url.Append("&skip_dup=1");
            if (parameters.DebugMode)
                url.Append("&debug=1");
            if (parameters.ExistingUser)
                url.Append("&existing_user=1");

            // Construct encrypted data params and append to url
            StringBuilder data = new StringBuilder();
            // Add UNIX timestamp as system date
            long timestamp = UnixTimestamp();
            data.Append("&system_date=").Append(timestamp.ToString());

            data.Append("&windows_aid=").Append(Uri.EscapeUriString(parameters.WindowsAid));
            data.Append("&app_name=").Append(Uri.EscapeUriString(parameters.AppName));
            data.Append("&app_version=").Append(Uri.EscapeUriString(parameters.AppVersion));
            data.Append("&os_id=").Append(Uri.EscapeUriString(parameters.ASHWID));
            if (parameters.UserAgent != null)
                data.Append("&user_agent=").Append(Uri.EscapeUriString(parameters.UserAgent));
            if (parameters.AppAdTracking)
                data.Append("&app_ad_tracking=1");
            else
                data.Append("&app_ad_tracking=0");

            if (revenue > 0)
                data.Append("&revenue=").Append(Uri.EscapeUriString(revenue.ToString(parameters.culture)));
            if (currency != null)
                data.Append("&currency_code=").Append(Uri.EscapeUriString(currency));
            if (refId != null)
                data.Append("&advertiser_ref_id=").Append(Uri.EscapeUriString(refId));

            if (parameters.Age > 0)
                data.Append("&age=").Append(Uri.EscapeUriString(parameters.Age.ToString(parameters.culture)));
            data.Append("&altitude=").Append(Uri.EscapeUriString(parameters.Altitude.ToString()));
            if (parameters.EventContentType != null)
                data.Append("&content_type=").Append(Uri.EscapeUriString(parameters.EventContentType));
            if (parameters.EventContentId != null)
                data.Append("&content_id=").Append(Uri.EscapeUriString(parameters.EventContentId));
            data.Append("&level=").Append(parameters.EventLevel.ToString());
            data.Append("&quantity=").Append(parameters.EventQuantity.ToString());
            if (parameters.EventSearchString != null)
                data.Append("&search_string=").Append(Uri.EscapeUriString(parameters.EventSearchString));
            data.Append("&rating=").Append(Uri.EscapeUriString(parameters.EventRating.ToString()));
            if (parameters.EventDate1 != null)
                data.Append("&date1=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate1).ToString()));
            if (parameters.EventDate2 != null)
                data.Append("&date2=").Append(Uri.EscapeUriString(UnixTimestamp(parameters.EventDate2).ToString()));
            if (parameters.EventAttribute1 != null)
                data.Append("&attribute_sub1=").Append(Uri.EscapeUriString(parameters.EventAttribute1));
            if (parameters.EventAttribute2 != null)
                data.Append("&attribute_sub2=").Append(Uri.EscapeUriString(parameters.EventAttribute2));
            if (parameters.EventAttribute3 != null)
                data.Append("&attribute_sub3=").Append(Uri.EscapeUriString(parameters.EventAttribute3));
            if (parameters.EventAttribute4 != null)
                data.Append("&attribute_sub4=").Append(Uri.EscapeUriString(parameters.EventAttribute4));
            if (parameters.EventAttribute5 != null)
                data.Append("&attribute_sub5=").Append(Uri.EscapeUriString(parameters.EventAttribute5));
            if (parameters.DeviceBrand != null)
                data.Append("&device_brand=").Append(Uri.EscapeUriString(parameters.DeviceBrand));
            if (parameters.DeviceModel != null)
                data.Append("&device_model=").Append(Uri.EscapeUriString(parameters.DeviceModel));
            if (parameters.DeviceType != null)
                data.Append("&device_type=").Append(Uri.EscapeUriString(parameters.DeviceType));
            if (parameters.FacebookUserId != null)
                data.Append("&facebook_user_id=").Append(Uri.EscapeUriString(parameters.FacebookUserId));
            if (parameters.Gender != MATGender.NONE)
                data.Append("&gender=").Append(Uri.EscapeUriString(((int)parameters.Gender).ToString(parameters.culture)));
            if (parameters.GoogleUserId != null)
                data.Append("&google_user_id=").Append(Uri.EscapeUriString(parameters.GoogleUserId));
            if (parameters.IsPayingUser != false)
                data.Append("&is_paying_user=1");
            if (parameters.Latitude != 0)
                data.Append("&latitude=").Append(Uri.EscapeUriString(parameters.Latitude.ToString(parameters.culture)));
            if (parameters.Longitude != 0)
                data.Append("&longitude=").Append(Uri.EscapeUriString(parameters.Longitude.ToString(parameters.culture)));
            if (parameters.PhoneNumber != null)
            {
                data.Append("&user_phone_md5=").Append(Uri.EscapeUriString(parameters.PhoneNumberMd5));
                data.Append("&user_phone_sha1=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha1));
                data.Append("&user_phone_sha256=").Append(Uri.EscapeUriString(parameters.PhoneNumberSha256));
            }
            if (parameters.TwitterUserId != null)
                data.Append("&twitter_user_id=").Append(Uri.EscapeUriString(parameters.TwitterUserId));
            if (parameters.UserEmail != null)
            {
                data.Append("&user_email_md5=").Append(Uri.EscapeUriString(parameters.UserEmailMd5));
                data.Append("&user_email_sha1=").Append(Uri.EscapeUriString(parameters.UserEmailSha1));
                data.Append("&user_email_sha256=").Append(Uri.EscapeUriString(parameters.UserEmailSha256));
            }
            if (parameters.UserId != null)
                data.Append("&user_id=").Append(Uri.EscapeUriString(parameters.UserId));
            if (parameters.UserName != null)
            {
                data.Append("&user_name_md5=").Append(Uri.EscapeUriString(parameters.UserNameMd5));
                data.Append("&user_name_sha1=").Append(Uri.EscapeUriString(parameters.UserNameSha1));
                data.Append("&user_name_sha256=").Append(Uri.EscapeUriString(parameters.UserNameSha256));
            }

            // Add event items to url as json string
            if (eventItems != null)
                data.Append("&site_event_items=").Append(Uri.EscapeUriString(JsonConvert.SerializeObject(eventItems)));

            if (parameters.matRequest != null)
                parameters.matRequest.ParamsToBeEncrypted(data.ToString());

            // Encrypt data string
            string dataStr = parameters.urlEncrypter.Encrypt(data.ToString());
            url.Append("&data=").Append(dataStr);

            url.Append("&response_format=json");

            if (parameters.matRequest != null)
                parameters.matRequest.ConstructedRequest(url.ToString());

            return url.ToString();
        }
예제 #17
0
 // Add a url to event queue to send later
 internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List<MATEventItem> eventItems, MATParameters paramCopy)
 {
     Debug.WriteLine("Processing tracking request");
     lock (syncLock)
     {
         Task.Factory.StartNew(() =>
         {
             DumpQueue();
             string url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, paramCopy);
             AddToQueue(url, 0);
             DumpQueue();
         });
        }
 }
예제 #18
0
 protected internal MATEventQueue(MATParameters parameters)
 {
     this.parameters = parameters;
     syncLock = new Object();
 }
예제 #19
0
 internal MATUrlRequester(MATParameters parameters, MATEventQueue eventQueue)
 {
     this.parameters = parameters;
     this.eventQueue = eventQueue;
 }
예제 #20
0
        // Add a url to event queue to send later
        internal void ProcessTrackingRequest(string action, string eventName, double revenue, string currency, string refId, List<MATEventItem> eventItems, MATParameters paramCopy)
        {
            Debug.WriteLine("Processing tracking request");
            lock (syncLock)
            {
                Task.Factory.StartNew(() =>
                {
                    DumpQueue();
                    string url = MATUrlBuilder.BuildUrl(action, eventName, revenue, currency, refId, eventItems, paramCopy);
                    // Convert event items to correct JSON
                    var jsonData = JsonConvert.SerializeObject(new { data = eventItems }, Formatting.None);

                    AddToQueue(url, jsonData, 0);
                    DumpQueue();
                });
               }
        }