public void TestPush() { var expected = "GM250"; var test = "250GM"; var sb = new StringBuilder(test); sb.Push(char.IsNumber); var actual = sb.ToString(); Assert.AreEqual(expected, actual); }
/// <summary> /// Renders the required JavaScript onto the page for Google Analytics tracking. /// Recommended to include this within the head element of the page. /// </summary> public static IHtmlString Render() { var gaq = new StringBuilder(Scripts.ScriptStart); gaq.Push(string.Format(Scripts.SetAccount, Account)); // Events foreach (var gaEvent in Current.Events) gaq.Push(Scripts.TrackEvent.FormatWith(gaEvent)); // Social foreach (var socialEvent in Current.SocialEvents) gaq.Push(string.IsNullOrWhiteSpace(socialEvent.PagePath) ? Scripts.TrackSocial.FormatWith(socialEvent) : Scripts.TrackSocialWithPagePath.FormatWith(socialEvent)); // Transaction if (Current.Transactions.Any()) foreach (var trans in Current.Transactions) gaq.Push(Scripts.AddTrans.FormatWith(trans)); // Items if (Current.Items.Any()) foreach (var item in Current.Items) gaq.Push(Scripts.AddItem.FormatWith(item)); // Page view gaq.Push(string.IsNullOrWhiteSpace(Current.VirtualPageUrl) ? Scripts.TrackPageView : string.Format(Scripts.TrackVirtualPageView, Current.VirtualPageUrl.TrimStart('/'))); // Track transaction if (Current.Transactions.Any()) gaq.Push(Scripts.TrackTrans); gaq.AppendLine(Scripts.ScriptEnd); return new HtmlString(gaq.ToString()); }