Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue that prevented Google Tag Manager to create scripts and delete connection #4457

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public bool SaveConfig(int portalId, IDictionary<string, string> values, ref boo
/// <returns>The string representing a boolean after the correction.</returns>
private string HandleCustomBoolean(string value)
{
if (value.Trim().Equals("true", StringComparison.OrdinalIgnoreCase))
if ((value ?? string.Empty).Trim().Equals("true", StringComparison.OrdinalIgnoreCase))
{
return "true";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,6 +182,11 @@ public bool SaveConfig(int portalId, IDictionary<string, string> values, ref boo
});

AnalyticsConfiguration.SaveConfig("GoogleTagManager", config);

if (!isDeactivating)
{
this.EnsureScriptInConfig();
}
}

return isValid;
Expand All @@ -190,6 +198,43 @@ public bool SaveConfig(int portalId, IDictionary<string, string> values, ref boo
}
}

/// <summary>
/// Check if there's an AnalyticsEngine element in siteanalytics.config for this connector. If not, adds the default one.
/// </summary>
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);
}
}

/// <summary>
/// Handles custom conversion from "true" => "true"
/// Anything else to "" to support the strange knockout handling of string as booleans.
Expand All @@ -198,7 +243,7 @@ public bool SaveConfig(int portalId, IDictionary<string, string> values, ref boo
/// <returns>The string representing a boolean after the correction.</returns>
private string HandleCustomBoolean(string value)
{
if (value.Trim().Equals("true", StringComparison.OrdinalIgnoreCase))
if ((value ?? string.Empty).Trim().Equals("true", StringComparison.OrdinalIgnoreCase))
{
return "true";
}
Expand Down
4 changes: 2 additions & 2 deletions DNN Platform/Connectors/GoogleTagManager/Scripts/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down