public bool CheckCampaignLimits(string triggerEvent, IDictionary <string, string> payload, SwrveQAUser qaUser) { DateTime now = SwrveHelper.GetNow(); if (!CanTrigger(triggerEvent, payload, qaUser)) { LogAndAddReason("There is no trigger in " + Id + " that matches " + triggerEvent, qaUser); return(false); } if (!IsActive(qaUser)) { return(false); } if (!CheckImpressions(qaUser)) { return(false); } if (!string.Equals(triggerEvent, "Swrve.Messages.showAtSessionStart", StringComparison.OrdinalIgnoreCase) && IsTooSoonToShowMessageAfterLaunch(now)) { LogAndAddReason("{Campaign throttle limit} Too soon after launch. Wait until " + showMessagesAfterLaunch.ToString("HH\\:mm\\:ss zzz"), qaUser); return(false); } if (IsTooSoonToShowMessageAfterDelay(now)) { LogAndAddReason("{Campaign throttle limit} Too soon after last message. Wait until " + showMessagesAfterDelay.ToString("HH\\:mm\\:ss zzz"), qaUser); return(false); } return(true); }
public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (CanMakeSessionRequest()) { lastSessionRequestTime = SwrveHelper.GetMilliseconds(); string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/session"); Dictionary <string, object> dictionary = new Dictionary <string, object>(); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = campaignsDownloaded.GetEnumerator(); while (enumerator.MoveNext()) { int key = enumerator.Current.Key; string value = enumerator.Current.Value; Dictionary <string, object> dictionary2 = new Dictionary <string, object>(); dictionary2.Add("id", key); dictionary2.Add("reason", (value == null) ? string.Empty : value); dictionary2.Add("loaded", value == null); list.Add(dictionary2); } dictionary.Add("campaigns", list); Dictionary <string, string> deviceInfo = swrve.GetDeviceInfo(); dictionary.Add("device", deviceInfo); MakeRequest(endpoint, dictionary); } } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
public virtual void SaveSecure(string tag, string data, string userId = null) { if (string.IsNullOrEmpty(data)) { return; } bool saved = false; try { string saveFileName = GetFileName(tag, userId); SwrveLog.Log("Saving: " + saveFileName, "storage"); CrossPlatformFile.SaveText(saveFileName, data); string signatureFileName = saveFileName + SIGNATURE_SUFFIX; string signature = SwrveHelper.CreateHMACMD5(data, uniqueKey); CrossPlatformFile.SaveText(signatureFileName, signature); saved = true; } catch (Exception e) { SwrveLog.LogError(e.ToString(), "storage"); } if (!saved) { SwrveLog.LogWarning(tag + " not saved!", "storage"); } }
protected void HandleDeeplink(string url, string actionType) { if (actionType == null) { actionType = SWRVE_AD_REENGAGE; } if (!IsSwrveDeeplink(url)) { return; } Dictionary <string, string> queryParams = SwrveHelper.GetUriQueryParameters((new Uri(url)).Query); if (queryParams.Count > 0) { string adSource = queryParams [SWRVE_AD_SOURCE]; string campaignName = queryParams [SWRVE_AD_CAMPAIGN]; string campaignID = queryParams [SWRVE_AD_CONTENT]; string getRequest = CreateCampaignUrl(campaignID); container.StartCoroutine(GetExternalCampaign_Coroutine(getRequest)); QueueDeeplinkGenericEvent(adSource, campaignID, campaignName, actionType); } }
public void PushNotification(RemoteNotification notification) #endif { try { String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/push"); if (CanMakePushNotificationRequest()) { lastPushNotificationRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <string, object> pushJson = new Dictionary <string, object>(); pushJson.Add("alert", notification.alertBody); pushJson.Add("sound", notification.soundName); pushJson.Add("badge", notification.applicationIconBadgeNumber); if (notification.userInfo != null && notification.userInfo.Contains(PushTrackingKey)) { string pushId = notification.userInfo[PushTrackingKey].ToString(); pushJson.Add("id", pushId); } MakeRequest(endpoint, pushJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
/// <summary> /// Obtains the device token if available. /// </summary> /// <returns> /// If the token was correctly obtained. /// </returns> public bool ObtainIOSDeviceToken() { if (config.PushNotificationEnabled) { byte[] token = NotificationServices.deviceToken; if (token != null) { // Send token as user update and to Babble if QA user string hexToken = SwrveHelper.FilterNonAlphanumeric(System.BitConverter.ToString(token)); bool sendDeviceInfo = (iOSdeviceToken != hexToken); if (sendDeviceInfo) { iOSdeviceToken = hexToken; // Save device token for future launches storage.Save(iOSdeviceTokenSave, iOSdeviceToken); SendDeviceInfo(); if (qaUser != null) { qaUser.UpdateDeviceInfo(); } } return(true); } } return(false); }
public virtual void SaveSecure(string tag, string data, string userId = null) { if (!string.IsNullOrEmpty(data)) { bool flag = false; try { string fileName = GetFileName(tag, userId); SwrveLog.Log("Saving: " + fileName, "storage"); CrossPlatformFile.SaveText(fileName, data); string path = fileName + "_SGT"; string data2 = SwrveHelper.CreateHMACMD5(data, uniqueKey); CrossPlatformFile.SaveText(path, data2); flag = true; } catch (Exception ex) { SwrveLog.LogError(ex.ToString(), "storage"); } if (!flag) { SwrveLog.LogWarning(tag + " not saved!", "storage"); } } }
public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (CanMakeSessionRequest()) { lastSessionRequestTime = SwrveHelper.GetMilliseconds(); String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/session"); Dictionary <string, object> talkSessionJson = new Dictionary <string, object> (); // Add campaigns (downloaded or not) to request IList <object> campaignsJson = new List <object> (); Dictionary <int, string> .Enumerator campaignIt = campaignsDownloaded.GetEnumerator(); while (campaignIt.MoveNext()) { int id = campaignIt.Current.Key; string reason = campaignIt.Current.Value; Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", id); campaignInfo.Add("reason", (reason == null) ? string.Empty : reason); campaignInfo.Add("loaded", (reason == null)); campaignsJson.Add(campaignInfo); } talkSessionJson.Add("campaigns", campaignsJson); // Add device info to request Dictionary <string, string> deviceJson = swrve.GetDeviceInfo(); talkSessionJson.Add("device", deviceJson); MakeRequest(endpoint, talkSessionJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
private string getNativeLanguage() { string language = null; if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass localeJavaClass = new AndroidJavaClass("java.util.Locale")) { AndroidJavaObject defaultLocale = localeJavaClass.CallStatic <AndroidJavaObject>("getDefault"); language = defaultLocale.Call <string>("getLanguage"); string country = defaultLocale.Call <string>("getCountry"); if (!string.IsNullOrEmpty(country)) { language += "-" + country; } string variant = defaultLocale.Call <string>("getVariant"); if (!string.IsNullOrEmpty(variant)) { language += "-" + variant; } } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get the device language, make sure you are running on an Android device: " + exp.ToString()); } } return(language); }
private bool CanMakeTimedRequest(long lastTime, long intervalTime) { if (CanMakeRequest() && (lastTime == 0 || SwrveHelper.GetMilliseconds() - lastTime > 1000)) { return(true); } return(false); }
public void Trigger(string eventName, SwrveBaseMessage baseMessage) { try { if (CanMakeTriggerRequest()) { lastTriggerRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <int, string> _reasons = campaignReasons; Dictionary <int, SwrveBaseMessage> _messages = campaignMessages; campaignReasons = new Dictionary <int, string>(); campaignMessages = new Dictionary <int, SwrveBaseMessage>(); String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger"); Dictionary <string, object> triggerJson = new Dictionary <string, object> (); triggerJson.Add("trigger_name", eventName); triggerJson.Add("displayed", baseMessage != null); triggerJson.Add("reason", baseMessage == null ? "The loaded campaigns returned no conversation or message" : string.Empty); // Add campaigns that were not displayed IList <object> campaignsJson = new List <object> (); Dictionary <int, string> .Enumerator campaignIt = _reasons.GetEnumerator(); while (campaignIt.MoveNext()) { int campaignId = campaignIt.Current.Key; String reason = campaignIt.Current.Value; Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", campaignId); campaignInfo.Add("displayed", false); campaignInfo.Add("reason", (reason == null) ? string.Empty : reason); if (_messages.ContainsKey(campaignId)) { SwrveBaseMessage _baseMessage = _messages [campaignId]; campaignInfo.Add(_baseMessage.GetBaseMessageType() + "_id", _baseMessage.Id); } campaignsJson.Add(campaignInfo); } // Add campaign that was shown, if available if (baseMessage != null) { Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", baseMessage.Campaign.Id); campaignInfo.Add("displayed", true); campaignInfo.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id); campaignInfo.Add("reason", string.Empty); campaignsJson.Add(campaignInfo); } triggerJson.Add("campaigns", campaignsJson); MakeRequest(endpoint, triggerJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
private void UpdateNativeUserId() { if (SwrveHelper.IsOnDevice()) { try { AndroidGetBridge().Call(SetUserIdName, this.profileManager.userId); } catch (Exception exp) { SwrveLog.LogWarning("Couldn't set userId from Android: " + exp.ToString()); } } }
public virtual string LoadSecure(string tag, string userId = null) { string text = null; string fileName = GetFileName(tag, userId); try { string text2 = fileName + "_SGT"; if (CrossPlatformFile.Exists(fileName)) { text = CrossPlatformFile.LoadText(fileName); if (!string.IsNullOrEmpty(text)) { string text3 = null; if (CrossPlatformFile.Exists(text2)) { text3 = CrossPlatformFile.LoadText(text2); } else { SwrveLog.LogError("Could not read signature file: " + text2); text = null; } if (!string.IsNullOrEmpty(text3)) { string value = SwrveHelper.CreateHMACMD5(text, uniqueKey); if (string.IsNullOrEmpty(value)) { SwrveLog.LogError("Could not compute signature for data in file " + fileName); text = null; } else if (!text3.Equals(value)) { if (callback != null) { callback(); } SwrveLog.LogError("Signature validation failed for " + fileName); text = null; } } } else { SwrveLog.LogError("Could not read file " + fileName); } } } catch (Exception ex) { SwrveLog.LogError(ex.ToString(), "storage"); } return(text); }
public void LocationUserUpdate(Dictionary <string, string> map) { if (SwrveHelper.IsOnDevice()) { try { AndroidGetBridge().CallStatic(SwrveLocationUserUpdateName, Json.Serialize(map)); } catch (Exception exp) { SwrveLog.LogWarning("Couldn't update location details from Android: " + exp.ToString()); } } }
private bool CanMakeTimedRequest(long lastTime, long intervalTime) { if (CanMakeRequest()) { if (lastTime == 0 || (SwrveHelper.GetMilliseconds() - lastTime) > SessionInterval) { return(true); } } return(false); }
public string GetPlotNotifications() { if (SwrveHelper.IsOnDevice()) { try { return(AndroidGetBridge().CallStatic <string>(SwrveGetPlotNotificationsName)); } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get plot notifications from Android: " + exp.ToString()); } } return("[]"); }
private void startNativeLocation() { if (SwrveHelper.IsOnDevice()) { try { AndroidGetBridge().CallStatic(SwrveStartLocationName); startedPlot = true; } catch (Exception exp) { SwrveLog.LogWarning("Couldn't start Swrve location from Android: " + exp.ToString()); } } }
public void Trigger(string eventName, SwrveBaseMessage baseMessage) { try { if (!CanMakeTriggerRequest()) { return; } lastTriggerRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <int, string> dictionary = campaignReasons; Dictionary <int, SwrveBaseMessage> dictionary2 = campaignMessages; campaignReasons = new Dictionary <int, string>(); campaignMessages = new Dictionary <int, SwrveBaseMessage>(); string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger"); Dictionary <string, object> dictionary3 = new Dictionary <string, object>(); dictionary3.Add("trigger_name", eventName); dictionary3.Add("displayed", baseMessage != null); dictionary3.Add("reason", (baseMessage == null) ? "The loaded campaigns returned no conversation or message" : string.Empty); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { int key = enumerator.Current.Key; string value = enumerator.Current.Value; Dictionary <string, object> dictionary4 = new Dictionary <string, object>(); dictionary4.Add("id", key); dictionary4.Add("displayed", false); dictionary4.Add("reason", (value == null) ? string.Empty : value); if (dictionary2.ContainsKey(key)) { SwrveBaseMessage swrveBaseMessage = dictionary2[key]; dictionary4.Add(swrveBaseMessage.GetBaseMessageType() + "_id", swrveBaseMessage.Id); } list.Add(dictionary4); } if (baseMessage != null) { Dictionary <string, object> dictionary4 = new Dictionary <string, object>(); dictionary4.Add("id", baseMessage.Campaign.Id); dictionary4.Add("displayed", true); dictionary4.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id); dictionary4.Add("reason", string.Empty); list.Add(dictionary4); } dictionary3.Add("campaigns", list); MakeRequest(endpoint, dictionary3); } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
private void CopyToClipboard(string content) { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass swrveAndroidCommonClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { swrveAndroidCommonClass.CallStatic(CopyToClipboardName, content); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't copy text to clipboard: " + exp.ToString()); } } }
public static void updateQAUser() { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass swrveAndroidCommonClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { swrveAndroidCommonClass.CallStatic(QaUserUpdateName); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't update qauser from Android: " + exp.ToString()); } } }
private AndroidJavaObject AndroidGetBridge() { if (SwrveHelper.IsOnDevice()) { using (AndroidJavaClass unityPlayerClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { if (null == _androidBridge || !unityPlayerClass.CallStatic <bool> (IsInitialisedName)) { _androidBridge = new AndroidJavaObject(SwrveAndroidUnityCommonName, GetNativeDetails()); } } } return(_androidBridge); }
private void ClearAllAuthenticatedNotifications() { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass swrveAndroidCommonClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { swrveAndroidCommonClass.CallStatic(ClearAllUserAuthenticatedNotificationsName); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't clear all authenticated notifications from Android: " + exp.ToString()); } } }
public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (this.CanMakeSessionRequest()) { this.lastSessionRequestTime = SwrveHelper.GetMilliseconds(); string endpoint = this.getEndpoint(string.Concat(new string[] { "talk/game/", this.swrve.ApiKey, "/user/", this.swrve.UserId, "/session" })); Dictionary <string, object> dictionary = new Dictionary <string, object>(); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = campaignsDownloaded.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, string> current = enumerator.Current; int key = current.Key; KeyValuePair <int, string> current2 = enumerator.Current; string value = current2.Value; list.Add(new Dictionary <string, object> { { "id", key }, { "reason", (value != null) ? value : string.Empty }, { "loaded", value == null } }); } dictionary.Add("campaigns", list); Dictionary <string, string> deviceInfo = this.swrve.GetDeviceInfo(); dictionary.Add("device", deviceInfo); this.MakeRequest(endpoint, dictionary); } } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
private string AndroidGetTimezone() { if (SwrveHelper.IsOnDevice()) { try { AndroidJavaObject cal = new AndroidJavaObject("java.util.GregorianCalendar"); return(cal.Call <AndroidJavaObject>("getTimeZone").Call <string>("getID")); } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get the device timezone, make sure you are running on an Android device: " + exp.ToString()); } } return(null); }
public static bool IsSupportedAndroidVersion() { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass swrveAndroidCommonClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { return(swrveAndroidCommonClass.CallStatic <bool>(SwrveIsOSSupportedVersionName)); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get supported OS version from Android: " + exp.ToString()); } } return(false); }
public static string GetAndroidDeviceType() { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass swrveAndroidCommonClass = new AndroidJavaClass(SwrveAndroidUnityCommonName)) { return(swrveAndroidCommonClass.CallStatic <string>(SwrveGetOSDeviceTypeName)); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get OS device type from Android: " + exp.ToString()); } } return("mobile"); // if there is no native response, we default to "mobile" }
public string GetInfluencedDataJson() { if (SwrveHelper.IsOnDevice()) { try { using (AndroidJavaClass pushSupportClass = new AndroidJavaClass(SwrvePushSupport)) { return(pushSupportClass.CallStatic <string>(GetInfluencedDataJsonName)); } } catch (Exception exp) { SwrveLog.LogWarning("Couldn't get influence data from Android: " + exp.ToString()); } } return(null); }
public virtual IEnumerator Post(string url, byte[] encodedData, Dictionary <string, string> headers, Action <RESTResponse> listener) { if (!Application.isEditor) { headers = AddMetricsHeader(headers); } long start = SwrveHelper.GetMilliseconds(); using (var www = CrossPlatformUtils.MakeWWW(url, encodedData, headers)) { yield return(www); long wwwTime = SwrveHelper.GetMilliseconds() - start; ProcessResponse(www, wwwTime, url, listener); } }
public bool IsActive(SwrveQAUser qaUser) { DateTime utcNow = SwrveHelper.GetUtcNow(); if (StartDate > utcNow) { LogAndAddReason($"Campaign {Id} not started yet (now: {utcNow}, end: {StartDate})", qaUser); return(false); } if (EndDate < utcNow) { LogAndAddReason($"Campaign {Id} has finished (now: {utcNow}, end: {EndDate})", qaUser); return(false); } return(true); }
public bool IsActive(SwrveQAUser qaUser) { DateTime utcNow = SwrveHelper.GetUtcNow(); if (this.StartDate > utcNow) { this.LogAndAddReason(string.Format("Campaign {0} not started yet (now: {1}, end: {2})", this.Id, utcNow, this.StartDate), qaUser); return(false); } if (this.EndDate < utcNow) { this.LogAndAddReason(string.Format("Campaign {0} has finished (now: {1}, end: {2})", this.Id, utcNow, this.EndDate), qaUser); return(false); } return(true); }