From 9bb8e27d78d0435f675517f6621c58a254875e94 Mon Sep 17 00:00:00 2001 From: Stefan Kamphuis Date: Sat, 6 Feb 2021 16:58:39 +0100 Subject: [PATCH 1/3] Fixes #4453 Delete GTM Connection --- DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js b/DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js index a3c974ecd91..b607cf30422 100644 --- a/DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js +++ b/DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js @@ -69,7 +69,7 @@ define(["jquery", "knockout", "templatePath/scripts/config", "templatePath/scrip // Set the isDeactivating flag to true to override the default save behaviour // Temporary workaround until delete functionality on connectors is improved - conn.configurations[6].value("true"); + conn.configurations[2].value("true"); wasDeactivated = true; conn.save(conn, e, onSaveComplete.bind(this, conn, conn.id)); } @@ -100,7 +100,7 @@ define(["jquery", "knockout", "templatePath/scripts/config", "templatePath/scrip // Set the isDeactivating flag to true to override the default save behaviour // Temporary workaround until delete functionality on connectors is improved - conn.configurations[6].value("true"); + conn.configurations[2].value("true"); wasDeactivated = true; conn.save(conn, e, onSaveComplete.bind(this, conn, conn.id)); } From ca5dc48070c9348d5936e74466290bdba3d28ee6 Mon Sep 17 00:00:00 2001 From: Stefan Kamphuis Date: Sun, 7 Feb 2021 17:00:29 +0100 Subject: [PATCH 2/3] Fixes #4453 Connector deletion not working --- .../Connectors/GoogleAnalytics/GoogleAnalyticsConnector.cs | 2 +- .../Connectors/GoogleTagManager/GoogleTagManagerConnector.cs | 2 +- .../Library/Services/Analytics/Config/AnalyticsConfiguration.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DNN Platform/Connectors/GoogleAnalytics/GoogleAnalyticsConnector.cs b/DNN Platform/Connectors/GoogleAnalytics/GoogleAnalyticsConnector.cs index 88915040827..bd08ac8d89f 100644 --- a/DNN Platform/Connectors/GoogleAnalytics/GoogleAnalyticsConnector.cs +++ b/DNN Platform/Connectors/GoogleAnalytics/GoogleAnalyticsConnector.cs @@ -246,7 +246,7 @@ public bool SaveConfig(int portalId, IDictionary values, ref boo /// The string representing a boolean after the correction. private string HandleCustomBoolean(string value) { - if (value.Trim().Equals("true", StringComparison.OrdinalIgnoreCase)) + if ((value ?? string.Empty).Trim().Equals("true", StringComparison.OrdinalIgnoreCase)) { return "true"; } diff --git a/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs b/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs index 3e3b952d8dd..8ea0aaee6e6 100644 --- a/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs +++ b/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs @@ -198,7 +198,7 @@ public bool SaveConfig(int portalId, IDictionary values, ref boo /// The string representing a boolean after the correction. private string HandleCustomBoolean(string value) { - if (value.Trim().Equals("true", StringComparison.OrdinalIgnoreCase)) + if ((value ?? string.Empty).Trim().Equals("true", StringComparison.OrdinalIgnoreCase)) { return "true"; } diff --git a/DNN Platform/Library/Services/Analytics/Config/AnalyticsConfiguration.cs b/DNN Platform/Library/Services/Analytics/Config/AnalyticsConfiguration.cs index 028b69ac497..06ca38540c8 100644 --- a/DNN Platform/Library/Services/Analytics/Config/AnalyticsConfiguration.cs +++ b/DNN Platform/Library/Services/Analytics/Config/AnalyticsConfiguration.cs @@ -84,7 +84,7 @@ public static AnalyticsConfiguration GetConfig(string analyticsEngineName) { var setting = new AnalyticsSetting(); setting.SettingName = nav.SelectSingleNode("SettingName").Value; - setting.SettingValue = nav.SelectSingleNode("SettingValue").Value; + setting.SettingValue = nav.SelectSingleNode("SettingValue")?.Value; Config.Settings.Add(setting); } From 9e3f042e08c8b9665c67df166f44a183b70e15d8 Mon Sep 17 00:00:00 2001 From: Stefan Kamphuis Date: Sun, 7 Feb 2021 17:01:06 +0100 Subject: [PATCH 3/3] Fixes #4452Remove need for manual editting of config file --- .../GoogleTagManagerConnector.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs b/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs index 8ea0aaee6e6..a75dce34ea9 100644 --- a/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs +++ b/DNN Platform/Connectors/GoogleTagManager/GoogleTagManagerConnector.cs @@ -6,7 +6,10 @@ namespace DNN.Connectors.GoogleTagManager { using System; using System.Collections.Generic; + using System.Web; + using System.Xml; + using DotNetNuke.Common; using DotNetNuke.Entities.Portals; using DotNetNuke.Services.Analytics.Config; using DotNetNuke.Services.Connections; @@ -179,6 +182,11 @@ public bool SaveConfig(int portalId, IDictionary values, ref boo }); AnalyticsConfiguration.SaveConfig("GoogleTagManager", config); + + if (!isDeactivating) + { + this.EnsureScriptInConfig(); + } } return isValid; @@ -190,6 +198,43 @@ public bool SaveConfig(int portalId, IDictionary values, ref boo } } + /// + /// Check if there's an AnalyticsEngine element in siteanalytics.config for this connector. If not, adds the default one. + /// + private void EnsureScriptInConfig() + { + var applicationMappath = HttpContext.Current.Server.MapPath("\\"); + var file = applicationMappath + "\\SiteAnalytics.config"; + var xdoc = new XmlDocument(); + xdoc.Load(file); + var found = false; + foreach (XmlNode engineTypeNode in xdoc.SelectNodes("/AnalyticsEngineConfig/Engines/AnalyticsEngine/EngineType")) + { + if (engineTypeNode.InnerText.Contains("DotNetNuke.Services.Analytics.GoogleTagManagerEngine")) + { + found = true; + break; + } + } + + if (!found) + { + var fileGtm = applicationMappath + "\\DesktopModules\\Connectors\\GoogleTagManager\\GoogleTagManager.config"; + var xdocGtm = new XmlDocument(); + xdocGtm.Load(fileGtm); + + var enginesElement = xdoc.SelectSingleNode("/AnalyticsEngineConfig/Engines"); + foreach (XmlNode engineNode in xdocGtm.SelectNodes("/AnalyticsEngineConfig/Engines/AnalyticsEngine")) + { + var engineFrag = xdoc.CreateDocumentFragment(); + engineFrag.InnerXml = engineNode.OuterXml; + enginesElement.AppendChild(engineFrag); + } + + xdoc.Save(file); + } + } + /// /// Handles custom conversion from "true" => "true" /// Anything else to "" to support the strange knockout handling of string as booleans.