Fix for Episerver Google Analytics context gadget for multi-hostname websites or dedicated edit server.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
using EPiServer.Core; | |
using EPiServer.GoogleAnalytics.Models; | |
namespace EPiServer.GoogleAnalytics.Controllers | |
{ | |
// Fixes Google Analytics context gadget for multi-hostname websites or dedicated edit server. | |
[Authorize(Roles = "Administrators,GoogleAnalyticsAdministrators,GoogleAnalyticsReaders")] | |
public class FixedGoogleAnalyticsContextController : EPiServer.GoogleAnalytics.Controllers.Controllers.ControllerBase | |
{ | |
protected override bool IsGlobal => false; | |
protected override AnalyticsViewModel GetViewModel(Guid gadgetId) | |
{ | |
return ViewModelBuilder.GetContextViewModel(gadgetId, User); | |
} | |
public override string GetPageUrl(ContentReference contentLink) | |
{ | |
var url = base.GetPageUrl(contentLink); | |
var uri = new Uri(url, UriKind.RelativeOrAbsolute); | |
// FIX: extract hostname filter for absolute urls | |
if (uri.IsAbsoluteUri) | |
{ | |
url = uri.PathAndQuery + ";ga:hostname==" + uri.Host; | |
} | |
return url; | |
} | |
protected override PartialViewResult PartialView(string viewName, object model) | |
{ | |
// this is required for Episerver to find the views (because this controller is out of module) | |
viewName = "/EPiServer/EPiServer.GoogleAnalytics/Views/Shared/" + viewName + ".ascx"; | |
return base.PartialView(viewName, model); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
using System.Web.Routing; | |
namespace Website.App_Start | |
{ | |
public static class Routes | |
{ | |
public static void Register(RouteCollection routes) | |
{ | |
// Fix for Google Analytics context gadget | |
routes.Insert(0, new Route( | |
"EPiServer/EPiServer.GoogleAnalytics/Context/{action}/{id}", | |
new RouteValueDictionary(new { controller = "FixedGoogleAnalyticsContext" }), | |
new RouteValueDictionary(new { action = "GraphData|PageSummaryView|ListsView" }), | |
new MvcRouteHandler() | |
)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment