diff --git a/Piwik.Tracker.Tests/PiwikTrackerTests.cs b/Piwik.Tracker.Tests/PiwikTrackerTests.cs index e79bb7a..1dbac5a 100644 --- a/Piwik.Tracker.Tests/PiwikTrackerTests.cs +++ b/Piwik.Tracker.Tests/PiwikTrackerTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Net.Http; using System.Web; @@ -24,6 +25,37 @@ public void SetUpTest() _sut = new PiwikTracker(SiteId, PiwikBaseUrl); } + [Test] + public void GetVisitorId_TwoComponentCookie_ReturnsCookieId() + { + //Arrange + HttpContext.Current = new HttpContext(new HttpRequest("filename", "http://url.com", "query"), new HttpResponse(new StringWriter())); + var cookies = HttpContext.Current.Request.Cookies; + cookies.Add(new HttpCookie("_pk_id.1.4ea4", "d32ffdf363c2f313.1610980363.")); + + //Act + var actual = _sut.GetVisitorId(); + + //Assert + Assert.That(actual, Is.Not.Null.Or.Empty); + Assert.That(actual, Is.EqualTo("d32ffdf363c2f313")); + } + + [Test] + public void GetRequest_TwoComponentCookie_SetsCorrectCookie() + { + //Arrange + HttpContext.Current = new HttpContext(new HttpRequest("filename", "http://url.com", "query"), new HttpResponse(new StringWriter())); + var cookies = HttpContext.Current.Request.Cookies; + cookies.Add(new HttpCookie("_pk_id.1.4ea4", "d32ffdf363c2f313.1610980363.")); + + //Act + var request = _sut.GetRequest(SiteId); + + //Assert + Assert.That(request, Does.Contain("&_id=d32ffdf363c2f313")); + } + [Test] [TestCase(Scopes.Page, 2)] [TestCase(Scopes.Event, 3)] diff --git a/Piwik.Tracker/PiwikTracker.cs b/Piwik.Tracker/PiwikTracker.cs index c53bc9e..a763134 100644 --- a/Piwik.Tracker/PiwikTracker.cs +++ b/Piwik.Tracker/PiwikTracker.cs @@ -181,10 +181,6 @@ public class PiwikTracker private string _configCookieDomain = ""; private readonly long _currentTs = (long)(DateTime.UtcNow - DateTimeUtils.UnixEpoch).TotalSeconds; private long _createTs; - private long? _visitCount = 0; - private long? _currentVisitTs; - private long? _lastVisitTs; - private long? _lastEcommerceOrderTs; private bool _sendImageResponse = true; /// @@ -1246,20 +1242,7 @@ protected bool LoadVisitorIdCookie() } _cookieVisitorId = parts[0]; // provides backward compatibility since getVisitorId() didn't change any existing VisitorId value _createTs = long.Parse(parts[1]); - if (!string.IsNullOrWhiteSpace(parts[2])) - { - _visitCount = long.Parse(parts[2]); - } - // _currentVisitTs is set for information / debugging purposes - _currentVisitTs = long.Parse(parts[3]); - if (!string.IsNullOrWhiteSpace(parts[4])) - { - _lastVisitTs = long.Parse(parts[4]); - } - if (!string.IsNullOrWhiteSpace(parts[5])) - { - _lastEcommerceOrderTs = long.Parse(parts[5]); - } + return true; } @@ -1511,9 +1494,6 @@ internal string GetRequest(int idSite) // Values collected from cookie "&_idts=" + _createTs + - "&_idvc=" + _visitCount + - ((_lastVisitTs != null) ? "&_viewts=" + _lastVisitTs : "") + - ((_lastEcommerceOrderTs != null) ? "&_ects=" + _lastEcommerceOrderTs : "") + // These parameters are set by the JS, but optional when using API (!string.IsNullOrEmpty(_plugins) ? _plugins : "") + @@ -1681,8 +1661,7 @@ protected void SetFirstPartyCookies() SetCookie("ses", "*", ConfigSessionCookieTimeout); // Set the 'id' cookie - var visitCount = _visitCount + 1; - var cookieValue = GetVisitorId() + "." + _createTs + "." + visitCount + "." + _currentTs + "." + _lastVisitTs + "." + _lastEcommerceOrderTs; + var cookieValue = GetVisitorId() + "." + _createTs; SetCookie("id", cookieValue, ConfigVisitorCookieTimeout); // Set the 'cvar' cookie