From 6fe269193abe2e1cd365ca223acb0773ed923832 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 24 Mar 2024 17:20:41 +0100 Subject: [PATCH] Expose visitedUrl when serializing any kind of visit, not only orphan visits --- docs/async-api/async-api.json | 13 +++++++------ docs/swagger/definitions/OrphanVisit.json | 6 +----- docs/swagger/definitions/Visit.json | 6 +++++- .../paths/v1_short-urls_{shortCode}_visits.json | 9 ++++++--- docs/swagger/paths/v2_domains_{domain}_visits.json | 9 ++++++--- docs/swagger/paths/v2_tags_{tag}_visits.json | 9 ++++++--- docs/swagger/paths/v2_visits_non-orphan.json | 9 ++++++--- module/Core/src/Visit/Entity/Visit.php | 2 +- .../PublishingUpdatesGeneratorTest.php | 1 + module/Core/test/Visit/Entity/VisitTest.php | 1 + 10 files changed, 40 insertions(+), 25 deletions(-) diff --git a/docs/async-api/async-api.json b/docs/async-api/async-api.json index 7cd838a8..83c424ea 100644 --- a/docs/async-api/async-api.json +++ b/docs/async-api/async-api.json @@ -232,6 +232,11 @@ "potentialBot": { "type": "boolean", "description": "Tells if Shlink thinks this visit comes potentially from a bot or crawler" + }, + "visitedUrl": { + "type": "string", + "nullable": true, + "description": "The originally visited URL that triggered the tracking of this visit" } }, "example": { @@ -247,7 +252,8 @@ "regionName": "California", "timezone": "America/Los_Angeles" }, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" } }, "OrphanVisit": { @@ -256,11 +262,6 @@ { "type": "object", "properties": { - "visitedUrl": { - "type": "string", - "nullable": true, - "description": "The originally visited URL that triggered the tracking of this visit" - }, "type": { "type": "string", "enum": [ diff --git a/docs/swagger/definitions/OrphanVisit.json b/docs/swagger/definitions/OrphanVisit.json index a8b4954a..897c6049 100644 --- a/docs/swagger/definitions/OrphanVisit.json +++ b/docs/swagger/definitions/OrphanVisit.json @@ -1,14 +1,10 @@ { "type": "object", - "required": ["visitedUrl", "type"], + "required": ["type"], "allOf": [{ "$ref": "./Visit.json" }], "properties": { - "visitedUrl": { - "type": ["string", "null"], - "description": "The originally visited URL that triggered the tracking of this visit" - }, "type": { "type": "string", "enum": [ diff --git a/docs/swagger/definitions/Visit.json b/docs/swagger/definitions/Visit.json index ecb6b9f9..c4589bb1 100644 --- a/docs/swagger/definitions/Visit.json +++ b/docs/swagger/definitions/Visit.json @@ -1,6 +1,6 @@ { "type": "object", - "required": ["referer", "date", "userAgent", "visitLocation"], + "required": ["referer", "date", "userAgent", "visitLocation", "potentialBot", "visitedUrl"], "properties": { "referer": { "type": "string", @@ -21,6 +21,10 @@ "potentialBot": { "type": "boolean", "description": "Tells if Shlink thinks this visit comes potentially from a bot or crawler" + }, + "visitedUrl": { + "type": ["string", "null"], + "description": "The originally visited URL that triggered the tracking of this visit" } } } diff --git a/docs/swagger/paths/v1_short-urls_{shortCode}_visits.json b/docs/swagger/paths/v1_short-urls_{shortCode}_visits.json index 71e70148..f3799f13 100644 --- a/docs/swagger/paths/v1_short-urls_{shortCode}_visits.json +++ b/docs/swagger/paths/v1_short-urls_{shortCode}_visits.json @@ -100,7 +100,8 @@ "date": "2015-08-20T05:05:03+04:00", "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0", "visitLocation": null, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": "https://t.co", @@ -115,14 +116,16 @@ "regionName": "California", "timezone": "America/Los_Angeles" }, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": null, "date": "2015-08-20T05:05:03+04:00", "userAgent": "some_web_crawler/1.4", "visitLocation": null, - "potentialBot": true + "potentialBot": true, + "visitedUrl": "https://s.test" } ], "pagination": { diff --git a/docs/swagger/paths/v2_domains_{domain}_visits.json b/docs/swagger/paths/v2_domains_{domain}_visits.json index d3acf60e..a477cb8e 100644 --- a/docs/swagger/paths/v2_domains_{domain}_visits.json +++ b/docs/swagger/paths/v2_domains_{domain}_visits.json @@ -103,7 +103,8 @@ "date": "2015-08-20T05:05:03+04:00", "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0", "visitLocation": null, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": "https://t.co", @@ -118,14 +119,16 @@ "regionName": "California", "timezone": "America/Los_Angeles" }, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": null, "date": "2015-08-20T05:05:03+04:00", "userAgent": "some_web_crawler/1.4", "visitLocation": null, - "potentialBot": true + "potentialBot": true, + "visitedUrl": "https://s.test" } ], "pagination": { diff --git a/docs/swagger/paths/v2_tags_{tag}_visits.json b/docs/swagger/paths/v2_tags_{tag}_visits.json index 2a0148ec..1f3dabf2 100644 --- a/docs/swagger/paths/v2_tags_{tag}_visits.json +++ b/docs/swagger/paths/v2_tags_{tag}_visits.json @@ -103,7 +103,8 @@ "date": "2015-08-20T05:05:03+04:00", "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0", "visitLocation": null, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": "https://t.co", @@ -118,14 +119,16 @@ "regionName": "California", "timezone": "America/Los_Angeles" }, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": null, "date": "2015-08-20T05:05:03+04:00", "userAgent": "some_web_crawler/1.4", "visitLocation": null, - "potentialBot": true + "potentialBot": true, + "visitedUrl": "https://s.test" } ], "pagination": { diff --git a/docs/swagger/paths/v2_visits_non-orphan.json b/docs/swagger/paths/v2_visits_non-orphan.json index da0bdd14..65b11252 100644 --- a/docs/swagger/paths/v2_visits_non-orphan.json +++ b/docs/swagger/paths/v2_visits_non-orphan.json @@ -94,7 +94,8 @@ "date": "2015-08-20T05:05:03+04:00", "userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0 Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0", "visitLocation": null, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": "https://t.co", @@ -109,14 +110,16 @@ "regionName": "California", "timezone": "America/Los_Angeles" }, - "potentialBot": false + "potentialBot": false, + "visitedUrl": "https://s.test" }, { "referer": null, "date": "2015-08-20T05:05:03+04:00", "userAgent": "some_web_crawler/1.4", "visitLocation": null, - "potentialBot": true + "potentialBot": true, + "visitedUrl": "https://s.test" } ], "pagination": { diff --git a/module/Core/src/Visit/Entity/Visit.php b/module/Core/src/Visit/Entity/Visit.php index 178fc283..86854945 100644 --- a/module/Core/src/Visit/Entity/Visit.php +++ b/module/Core/src/Visit/Entity/Visit.php @@ -163,6 +163,7 @@ class Visit extends AbstractEntity implements JsonSerializable 'userAgent' => $this->userAgent, 'visitLocation' => $this->visitLocation, 'potentialBot' => $this->potentialBot, + 'visitedUrl' => $this->visitedUrl, ]; if (! $this->isOrphan()) { return $base; @@ -170,7 +171,6 @@ class Visit extends AbstractEntity implements JsonSerializable return [ ...$base, - 'visitedUrl' => $this->visitedUrl, 'type' => $this->type->value, ]; } diff --git a/module/Core/test/EventDispatcher/PublishingUpdatesGeneratorTest.php b/module/Core/test/EventDispatcher/PublishingUpdatesGeneratorTest.php index 36fd6c8f..032c3263 100644 --- a/module/Core/test/EventDispatcher/PublishingUpdatesGeneratorTest.php +++ b/module/Core/test/EventDispatcher/PublishingUpdatesGeneratorTest.php @@ -68,6 +68,7 @@ class PublishingUpdatesGeneratorTest extends TestCase 'visitLocation' => null, 'date' => $visit->getDate()->toAtomString(), 'potentialBot' => false, + 'visitedUrl' => '', ], ], $update->payload); } diff --git a/module/Core/test/Visit/Entity/VisitTest.php b/module/Core/test/Visit/Entity/VisitTest.php index 62c56b2e..d9c50af6 100644 --- a/module/Core/test/Visit/Entity/VisitTest.php +++ b/module/Core/test/Visit/Entity/VisitTest.php @@ -30,6 +30,7 @@ class VisitTest extends TestCase 'userAgent' => $userAgent, 'visitLocation' => null, 'potentialBot' => $expectedToBePotentialBot, + 'visitedUrl' => $visit->visitedUrl, ], $visit->jsonSerialize()); }