protected void OnUpdateClick(object sender, EventArgs e) { try { var config = new AnalyticsConfiguration(); var setting = new AnalyticsSetting(); config.Settings = new AnalyticsSettingCollection(); setting.SettingName = "TrackingId"; setting.SettingValue = txtTrackingId.Text; config.Settings.Add(setting); setting = new AnalyticsSetting(); setting.SettingName = "UrlParameter"; setting.SettingValue = txtUrlParameter.Text; config.Settings.Add(setting); setting = new AnalyticsSetting(); setting.SettingName = "TrackForAdmin"; setting.SettingValue = chkTrackForAdmin.Checked.ToString().ToLowerInvariant(); config.Settings.Add(setting); AnalyticsConfiguration.SaveConfig("GoogleAnalytics", config); DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("Updated", LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
public static void DeleteConfig() { AnalyticsConfiguration analyticsConfiguration = new AnalyticsConfiguration() { Settings = new AnalyticsSettingCollection() }; AnalyticsSetting analyticsSetting = new AnalyticsSetting() { SettingName = "TrackingId", SettingValue = "" }; analyticsConfiguration.Settings.Add(analyticsSetting); AnalyticsSetting analyticsSetting1 = new AnalyticsSetting() { SettingName = "UrlParameter", SettingValue = "" }; analyticsConfiguration.Settings.Add(analyticsSetting1); AnalyticsSetting analyticsSetting2 = new AnalyticsSetting() { SettingName = "TrackForAdmin", SettingValue = "false" }; analyticsConfiguration.Settings.Add(analyticsSetting2); AnalyticsSetting analyticsSetting3 = new AnalyticsSetting() { SettingName = "AnonymizeIp", SettingValue = "false" }; analyticsConfiguration.Settings.Add(analyticsSetting3); AnalyticsSetting analyticsSetting4 = new AnalyticsSetting() { SettingName = "TrackUserId", SettingValue = "false" }; analyticsConfiguration.Settings.Add(analyticsSetting4); AnalyticsConfiguration.SaveConfig("GoogleAnalytics", analyticsConfiguration); }
public override void SetGoogleAnalyticsSettings(GoogleAnalyticsSettings newSettings) { var config = AnalyticsConfiguration.GetConfig("GoogleAnalytics"); if (config == null) { var isCommunityEdition = DotNetNukeContext.Current.Application.Name == "DNNCORP.CE"; config = new AnalyticsConfiguration(); if (!isCommunityEdition) { config.Rules = new AnalyticsRuleCollection(); } config.Settings = new AnalyticsSettingCollection(); if (!isCommunityEdition) { var enable = new AnalyticsSetting(); enable.SettingName = "Enable"; config.Settings.Add(enable); } var trackingId = new AnalyticsSetting(); trackingId.SettingName = "TrackingId"; config.Settings.Add(trackingId); } foreach (AnalyticsSetting setting in config.Settings) { switch (setting.SettingName.ToLower()) { case "enable": setting.SettingValue = newSettings.UseTracker.ToString(); break; case "trackingid": setting.SettingValue = newSettings.TrackerId; break; } } AnalyticsConfiguration.SaveConfig("GoogleAnalytics", config); }
public bool SaveConfig(int portalId, IDictionary <string, string> values, ref bool validated, out string customErrorMessage) { // Delete / Deactivation functionality added into SaveConfig because // As of DNN 9.2.2 you need to support multiple to get access to the Delete Connection functionality customErrorMessage = string.Empty; bool isValid; try { bool isDeactivating = false; bool.TryParse(values["isDeactivating"].ToLowerInvariant(), out isDeactivating); string trackingID; string urlParameter; bool trackForAdmin; isValid = true; if (isDeactivating) { trackingID = null; urlParameter = null; trackForAdmin = false; } else { trackingID = values["TrackingID"] != null ? values["TrackingID"].ToString().Trim() : String.Empty; urlParameter = values["UrlParameter"] != null ? values["UrlParameter"].ToString().Trim() : String.Empty; trackForAdmin = bool.TryParse(values["TrackAdministrators"].ToLowerInvariant(), out trackForAdmin); if (String.IsNullOrEmpty(trackingID)) { isValid = false; customErrorMessage = Localization.GetString("TrackingCodeFormat.ErrorMessage", Constants.LocalResourceFile); } } if (isValid) { var config = new AnalyticsConfiguration { Settings = new AnalyticsSettingCollection() }; var setting = new AnalyticsSetting { SettingName = "TrackingId", SettingValue = trackingID }; config.Settings.Add(setting); setting = new AnalyticsSetting { SettingName = "UrlParameter", SettingValue = urlParameter }; config.Settings.Add(setting); setting = new AnalyticsSetting { SettingName = "TrackForAdmin", SettingValue = trackForAdmin.ToString().ToLowerInvariant() }; config.Settings.Add(setting); AnalyticsConfiguration.SaveConfig("GoogleAnalytics", config); } return(isValid); } catch (Exception ex) { Exceptions.LogException(ex); return(false); } }
public bool SaveConfig(int portalId, IDictionary <string, string> values, ref bool validated, out string customErrorMessage) { customErrorMessage = string.Empty; bool isValid; try { string trackingID = values["TrackingID"].ToString().Trim(); string urlParameter = values["UrlParameter"].ToString().Trim(); bool trackForAdmin = false; trackForAdmin = bool.TryParse(values["TrackAdministrators"].ToLowerInvariant(), out trackForAdmin); if (!String.IsNullOrEmpty(trackingID) && IsValidGoogleAnalyticsCode(trackingID)) { isValid = true; var config = new AnalyticsConfiguration { Settings = new AnalyticsSettingCollection() }; var setting = new AnalyticsSetting { SettingName = "TrackingId", SettingValue = trackingID }; config.Settings.Add(setting); setting = new AnalyticsSetting { SettingName = "UrlParameter", SettingValue = urlParameter }; config.Settings.Add(setting); setting = new AnalyticsSetting { SettingName = "TrackForAdmin", SettingValue = trackForAdmin.ToString().ToLowerInvariant() }; config.Settings.Add(setting); AnalyticsConfiguration.SaveConfig("GoogleAnalytics", config); } else { customErrorMessage = Localization.GetString("TrackingCodeFormat.ErrorMessage", Constants.LocalResourceFile); isValid = false; } return(isValid); } catch (Exception ex) { Exceptions.LogException(ex); return(false); } }