public void AddEvent(GoogleAnalyticsEvent ev) { var tempData = GetTempData(); if (tempData != null) { tempData.AddEvent(ev); //these are detected by the google analytics taghelper and rendered } else { _log.LogWarning("failed to add google analytics event because tempData was null"); } }
public static void AddEvent(this ITempDataDictionary tempData, GoogleAnalyticsEvent analyticsEvent) { List <GoogleAnalyticsEvent> list; if (tempData.ContainsKey(GoogleAnalyticsEvent.TempDataKey)) { string json = (string)tempData[GoogleAnalyticsEvent.TempDataKey]; list = JsonConvert.DeserializeObject <List <GoogleAnalyticsEvent> >(json); } else { list = new List <GoogleAnalyticsEvent>(); } list.Add(analyticsEvent); tempData[GoogleAnalyticsEvent.TempDataKey] = JsonConvert.SerializeObject(list); }