public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData = null) { var globalScript = ""; if (_googleAnalyticsEcommerceSettings.AllowToDisableConsentCookie) { var enabled = await _cookiePreference.IsEnable(_workContext.CurrentCustomer, _storeContext.CurrentStore, GoogleAnalyticConst.ConsentCookieSystemName); if ((enabled.HasValue && !enabled.Value) || (!enabled.HasValue && !_googleAnalyticsEcommerceSettings.ConsentDefaultState)) { return(Content("")); } } var routeData = Url.ActionContext.RouteData; try { var controller = routeData.Values["controller"]; var action = routeData.Values["action"]; if (controller == null || action == null) { return(Content("")); } //Special case, if we are in last step of checkout, we can use order total for conversion value if (controller.ToString().Equals("checkout", StringComparison.OrdinalIgnoreCase) && action.ToString().Equals("completed", StringComparison.OrdinalIgnoreCase)) { var lastOrder = await GetLastOrder(); globalScript += await GetEcommerceScript(lastOrder); } else { globalScript += GetTrackingScript(); } } catch (Exception ex) { await _logger.InsertLog(Domain.Logging.LogLevel.Error, "Error creating scripts for google ecommerce tracking", ex.ToString()); } return(View("~/Plugins/Widgets.GoogleAnalytics/Views/PublicInfo.cshtml", globalScript)); }
public async Task <IViewComponentResult> InvokeAsync(string widgetZone, object additionalData = null) { if (_facebookPixelSettings.AllowToDisableConsentCookie) { var enabled = await _cookiePreference.IsEnable(_workContext.CurrentCustomer, _storeContext.CurrentStore, FacebookPixelConst.ConsentCookieSystemName); if ((enabled.HasValue && !enabled.Value) || (!enabled.HasValue && !_facebookPixelSettings.ConsentDefaultState)) { return(Content("")); } } //page if (widgetZone == FacebookPixelWidgetZone.Page) { return(View("~/Plugins/Widgets.FacebookPixel/Views/PublicInfo.cshtml", GetTrackingScript())); } //add to cart if (widgetZone == FacebookPixelWidgetZone.AddToCart) { var model = JsonConvert.DeserializeObject <FacebookAddToCartModelModel>(JsonConvert.SerializeObject(additionalData)); if (model != null) { return(View("~/Plugins/Widgets.FacebookPixel/Views/PublicInfo.cshtml", GetAddToCartScript(model))); } } //order details if (widgetZone == FacebookPixelWidgetZone.OrderDetails) { var orderId = additionalData as string; if (!string.IsNullOrEmpty(orderId)) { return(View("~/Plugins/Widgets.FacebookPixel/Views/PublicInfo.cshtml", await GetOrderScript(orderId))); } } return(Content("")); }