Add referrer to pageview event#2288
Conversation
…and remove "noreferrer" in all cases
…o-pageview-event-7.2
…o-pageview-event-7.4
…o-pageview-event-7.2
…o-pageview-event-7.4
…and remove "noreferrer" in all cases
…o-pageview-event-7.2
…o-pageview-event-7.4
…o-pageview-event-7.6.0-next
…o-pageview-event-7.2
…o-pageview-event-7.4
…o-pageview-event-7.6.0-next
|
Hi @artlowel, |
…eview-event-7.6.0-next
There was a problem hiding this comment.
I can't test this PR since i got the blank page error mentioned on slack https://dspace-org.slack.com/archives/CA15G9UE4/p1686132638587179
could you try to update both angular and rest PR
|
@atarix83 Can you try again please? We've updated the backend PR, and they should be compatible again |
atarix83
left a comment
There was a problem hiding this comment.
I'm testing it, but i'm not sure the result i got it's correct.
if i navigate to an item page following an internal application link, for example from the search page, i have as referrer the value "http://localhost:4000/".
Maybe i understood wrong, but should it contains also the page route? so in my test "http://localhost:4000/search"?
|
I tested it again, and I can't reproduce the problem you're having. I suspect your browser or an extension may be enforcing a referrer policy that prevents anything but the origin to be shared, for privacy reasons |
|
@artlowel : I think I've figured out the possible confusion. The testing instructions are slightly unclear, as I initially thought I had the same issue as @atarix83 . Here's what I was trying to test... depending on what is meant by "referrer", there's two different behaviors. Let me explain...
Assuming I understand this PR properly, we should be looking at this In any case, I ran a few basic tests today and can confirm that the
|
|
@tdonohue indeed: I mean the referrer parameter in the viewevents request, not the Referer header. The reason we can't use the Referer header, is because for a rest request made by the UI, it will always contain the current page, not the page the user navigated from. That's the issue this PR intends to solve |
tdonohue
left a comment
There was a problem hiding this comment.
👍 Thanks @artlowel . Verified this is working as described. I'm seeing the referrer param now passed to POST /api/statistics/viewevents calls. It looks to be correct in all examples that I can find. For instance, here's what the body looks like after clicking a search result after running a search on "cameron":
{
"targetId":"d10c32e6-2b14-41f7-be3e-46a41bbe1cb4",
"targetType":"item",
"referrer":"http://localhost:4000/search?query=cameron"
}
I've also verified that this results in the Solr document having a correct referrer:
{
"ip":"[redacted]",
"referrer":"http://localhost:4000/search?query=cameron",
...
"isBot":false,
"id":"d10c32e6-2b14-41f7-be3e-46a41bbe1cb4",
"type":2,
"owningColl":["282164f5-d325-4740-8dd1-fa4d6d3e7200"],
"owningComm":["0958c910-2037-42a9-81c7-dca80e3892b4"],
"time":"2023-06-12T15:55:00.172Z",
"statistics_type":"view",
"uid":"09ad75db-a17d-4e2e-b9ae-892898cf2720"},
This will be ready to merge as soon as a small bug in the backend PR is fixed.
|
I've tested it again, and having the same result. The POST request contains the correct referrer, but the solr record created contains always "http://localhost:4000/" solr Is probably a REST issue?? |
There was a problem hiding this comment.
👍 @artlowel : I retested this today (with the updated backend PR) and it's working for me.
I also realized that @atarix83 seems to be accidentally looking at the wrong Solr document in his tests. He was looking at the statistics_type:search_result. This PR instead is a fix for statistics_type:view .
Here's my testing process:
- Install both the frontend and backend PR. Running frontend in production mode
- Perform a search from the homepage for "testing".
- Now, click on an Item in the search results. This seems to generate two documents in Solr:
- First, it will generate a
statistics_type:search_resultthat looks like what @atarix83 was seeing. In this situation the "referrer" does appear to always be wrong.:
{ "ip":"[redacted]", "referrer":"http://localhost:4000/", ... "type":2, "owningColl":["c2aecee3-d59a-4e9c-9659-34283a719cda"], "owningComm":["c0e4de93-f506-4990-a840-d406f6f2ada7"], "time":"2023-06-16T15:21:31.668Z", "query":["testing"], "statistics_type":"search_result", "rpp":0, "sortBy":"score", "sortOrder":"desc", "page":1, "uid":"3673c2a4-7108-4c91-bbf2-d3382662ff7a"},- Second, this generates a
statistics_type:view, and thereferrershould reference the search that was performed (this is the bug fixed by this PR):
{ "ip":"[redacted]", "referrer":"http://localhost:4000/search?query=testing", ... "id":"16228f28-2f7e-44ec-9aa5-5898f89e8993", "type":2, "owningColl":["c2aecee3-d59a-4e9c-9659-34283a719cda"], "owningComm":["c0e4de93-f506-4990-a840-d406f6f2ada7"], "time":"2023-06-16T15:21:32.135Z", "statistics_type":"view", "uid":"8cd6bd9d-cbfb-4e99-b691-11ad872d1bea"}, - First, it will generate a
So, as you can see above... the referrer is now correct for view entries. But, it still is incorrect for search_result entries. I'm assuming that's expected behavior though, since this PR only claims to fix the view statistics. (Maybe we need a separate ticket for the search_result entries though? It's unclear to me how search_result is used though, and whether that's necessary)
References
Description
This PR sends a referrer param along with statistics view events, the referrer that lead the user to reach the UI page can be tracked, rather than the referrer of the rest call, which will always be the UI page you're currently on
It also removes the
rel="noopener noreferrer"param from all our listableObject links iftargetisn't_blank. Otherwise we still wouldn't have a referrer if a user got to a page using one of them. The attribute is left on fortarget="_blank"links for security reasonsInstructions for Reviewers
Visit the various pages that track views (home page, DSO pages) and verify in the browser's dev tools that the referrer param is sent, and that its value is correct. Either locally or when coming from a 3rd party site.
Keep in mind when using links from a 3rd party site, that the default referrer policy for all modern browsers is
strict-origin-when-cross-origin, so you'd only expect a referrer header when coming from another https site, and even then you'd only get the origin, not the exact path. Sites can specify exceptions to this using<meta>tags thoughChecklist
yarn lintyarn check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.