private BeaconEntity TrackPageEvent(string id, SpoofedHttpRequestBase spoofedRequest, PageEventType eventType, string page, string contactId, string data = null, string dataKey = null, IDictionary <string, string> extras = null, string monetaryValue = "0") { return(this.ExecuteTrackingRequest(string.Format("[PageVisit] : Page = {0} : Event = {1} : CID = {2}", page, eventType, contactId), delegate { if (string.IsNullOrWhiteSpace(id)) { throw HttpExceptionHelper.BadRequest("Bad Request", "No event identifier was specified."); } PageEventParameters pageEventParameters; if (id.IsGuid()) { pageEventParameters = new PageEventParameters(spoofedRequest.Url, new ID(id), eventType, contactId); } else { pageEventParameters = new PageEventParameters(spoofedRequest.Url, id, eventType, contactId); } pageEventParameters.Data = data; pageEventParameters.DataKey = dataKey; pageEventParameters.Extras = extras; if (eventType == PageEventType.Outcome) { decimal monetaryValue2; if (!decimal.TryParse(monetaryValue, out monetaryValue2)) { throw HttpExceptionHelper.BadRequest("Bad Request", "The outcome monetary value is invalid."); } pageEventParameters.MonetaryValue = monetaryValue2; } return this.trackingManager.TrackPageEvent(this.httpContextBase.Request, spoofedRequest, this.httpContextBase.Response, pageEventParameters); })); }
public BeaconEntity TrackGoal(string id, string page, string contactId = "", string data = null, string dataKey = null) { SpoofedHttpRequestBase spoofedRequest = this.GetSpoofedRequest(page, string.Empty); IDictionary <string, string> extras = null; if (HttpContext.Current != null && base.Request != null) { extras = WebUtil.ExtractPageEventParameters(base.Request.GetQueryNameValuePairs()); } return(this.TrackPageEvent(id, spoofedRequest, PageEventType.Goal, page, this.ResolveContactIdentifier(contactId, this.requestHelper.IsRequestInternal(spoofedRequest)), data, dataKey, extras, "0")); }
public BeaconEntity TrackPageVisit(string page, string referrer, string contactId = "") { SpoofedHttpRequestBase spoofedRequest = this.GetSpoofedRequest(page, referrer); string resolvedContactIdentifier = this.ResolveContactIdentifier(contactId, this.requestHelper.IsRequestInternal(spoofedRequest)); return(this.ExecuteTrackingRequest(string.Format("[PageVisit] : Page = {0} : Referrer = {1} : CID = {2}", page, referrer, resolvedContactIdentifier), delegate { PageVisitParameters parameters = new PageVisitParameters(spoofedRequest.Url, spoofedRequest.UrlReferrer, resolvedContactIdentifier); return this.trackingManager.TrackPageVisit(this.httpContextBase.Request, spoofedRequest, this.httpContextBase.Response, parameters); })); }
protected SpoofedHttpRequestBase GetSpoofedRequest(string page, string referrer) { Uri url; if (string.IsNullOrWhiteSpace(page) || !Uri.TryCreate(page, UriKind.Absolute, out url)) { throw HttpExceptionHelper.BadRequest("Bad Request", "No valid page was specified."); } Uri urlReferrer = null; if (!string.IsNullOrEmpty(referrer) && !Uri.TryCreate(referrer, UriKind.RelativeOrAbsolute, out urlReferrer)) { throw HttpExceptionHelper.BadRequest("Bad Request", "An invalid referrer was specified."); } SpoofedHttpRequestBase spoofedHttpRequestBase = new SpoofedHttpRequestBase(this.httpContextBase.Request); spoofedHttpRequestBase.SetUrl(url); spoofedHttpRequestBase.SetUrlReferrer(urlReferrer); return(spoofedHttpRequestBase); }
public BeaconEntity StopTracking(string contactId = "", bool killContact = false, string endTime = "") { if (this.httpContextBase != null && this.httpContextBase.Session != null) { string arg; if (!this.TryGetSessionId(out arg)) { HttpExceptionHelper.InternetServerError("Unexpected server error", "Session could not be initialized."); } this.logger.Debug(string.Format("[StopTracking]: CID: {0} SID: {1}", contactId, arg), null); HttpRequestBase httpRequestBase = this.httpContextBase.Request; if (!base.Request.Headers.Referrer.Host.Equals(base.Request.RequestUri.Host)) { SpoofedHttpRequestBase spoofedHttpRequestBase = new SpoofedHttpRequestBase(this.httpContextBase.Request); spoofedHttpRequestBase.SetUrl(base.Request.Headers.Referrer); httpRequestBase = spoofedHttpRequestBase; IDomainMatcher domainMatcher; Language language; if (!this.trackingManager.DomainIsValid(httpRequestBase, out domainMatcher, out language)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } TrackPageVisitArgs args = new TrackPageVisitArgs(this.sitecoreContext, this.trackerProvider, this.httpContextBase.Request, this.httpContextBase.Response, httpRequestBase, new PageVisitParameters(this.httpContextBase.Request.Url, null, contactId), domainMatcher, false); InitializeTrackingCookieProcessor initializeTrackingCookieProcessor = new InitializeTrackingCookieProcessor(); initializeTrackingCookieProcessor.Process(args); InitializeExternalTrackingProcessor initializeExternalTrackingProcessor = new InitializeExternalTrackingProcessor(); initializeExternalTrackingProcessor.Process(args); InitializeContextSiteProcessor initializeContextSiteProcessor = new InitializeContextSiteProcessor(); initializeContextSiteProcessor.Process(args); } else { Tracker.Initialize(); Tracker.Current.Session.SetClassification(0, 0, false); } if (!string.IsNullOrWhiteSpace(endTime)) { DateTime dateTime = DateTime.Parse(endTime, DateTimeFormatInfo.InvariantInfo); CurrentInteraction interaction = this.trackerProvider.Current.Interaction; Assert.IsNotNull(interaction, "interaction"); TimeSpan t = DateTime.UtcNow - DateUtil.ToUniversalTime(dateTime); interaction.EndDateTime = dateTime; interaction.StartDateTime -= t; Page[] pages = interaction.Pages; for (int i = 0; i < pages.Length; i++) { Page page = pages[i]; page.DateTime -= t; } } this.httpContextBase.Session.Abandon(); this.httpContextBase.Response.Cookies.Clear(); if (killContact) { DateTime expires = new DateTime(1979, 1, 1, 0, 0, 0, DateTimeKind.Utc); string[] allKeys = this.httpContextBase.Request.Cookies.AllKeys; for (int j = 0; j < allKeys.Length; j++) { string text = allKeys[j]; HttpCookie cookie = new HttpCookie(text) { Expires = expires, Value = string.Empty, Domain = this.httpContextBase.Request.Cookies.GetSafely(text).Domain }; this.httpContextBase.Response.Cookies.Add(cookie); } this.httpContextBase.Response.Cookies.Add(new HttpCookie("SC_ANALYTICS_GLOBAL_COOKIE") { Domain = "." + this.httpContextBase.Request.Url.Host, Value = string.Empty, Expires = expires }); } } return(new BeaconEntity { Id = "TBC", ContactId = string.Empty, SessionId = string.Empty, Url = string.Empty }); }
public void TriggerElementMatch(string id, string page, string referrer, string contactId = "") { SpoofedHttpRequestBase spoofedRequest = this.GetSpoofedRequest(page, referrer); this.TrackPageEvent(id, spoofedRequest, PageEventType.Element, page, this.ResolveContactIdentifier(contactId, this.requestHelper.IsRequestInternal(spoofedRequest)), null, null, null, "0"); }
public BeaconEntity TrackCampaign(string id, string page, string contactId = "") { SpoofedHttpRequestBase spoofedRequest = this.GetSpoofedRequest(page, string.Empty); return(this.TrackPageEvent(id, spoofedRequest, PageEventType.Campaign, page, this.ResolveContactIdentifier(contactId, this.requestHelper.IsRequestInternal(spoofedRequest)), null, null, null, "0")); }
public BeaconEntity TrackOutcome(string id, string page, string contactId = "", string monetaryValue = "0") { SpoofedHttpRequestBase spoofedRequest = this.GetSpoofedRequest(page, string.Empty); return(this.TrackPageEvent(id, spoofedRequest, PageEventType.Outcome, page, this.ResolveContactIdentifier(contactId, this.requestHelper.IsRequestInternal(spoofedRequest)), null, null, WebUtil.ExtractPageEventParameters(base.Request.GetQueryNameValuePairs()), monetaryValue)); }