Skip to content

[ENG-9907] Analytics are increasing (unique views) when a contributor is viewing their own content (Project) (BE)#11669

Open
antkryt wants to merge 1 commit intoCenterForOpenScience:feature/pbs-26-6from
antkryt:fix/ENG-9907-2
Open

[ENG-9907] Analytics are increasing (unique views) when a contributor is viewing their own content (Project) (BE)#11669
antkryt wants to merge 1 commit intoCenterForOpenScience:feature/pbs-26-6from
antkryt:fix/ENG-9907-2

Conversation

@antkryt
Copy link
Copy Markdown
Contributor

@antkryt antkryt commented Mar 31, 2026

Ticket

Purpose

do not count contrib views

Changes

Side Effects

QE Notes

CE Notes

Documentation

Comment on lines +361 to +417
class TestContributorExclusion:

def test_creator_pageview_not_recorded(self, app, mock_save):
user = AuthUserFactory()
project = ProjectFactory(creator=user)
payload = counted_usage_payload(
item_guid=project._id,
action_labels=['view', 'web'],
pageview_info={'page_url': f'https://osf.io/{project._id}/'},
)
resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=user.auth)
assert resp.status_code == 204
assert mock_save.call_count == 0

def test_read_contributor_pageview_not_recorded(self, app, mock_save):
creator = AuthUserFactory()
reader = AuthUserFactory()
project = ProjectFactory(creator=creator)
project.add_contributor(reader, permissions=READ, auth=Auth(creator))
payload = counted_usage_payload(
item_guid=project._id,
action_labels=['view', 'web'],
pageview_info={'page_url': f'https://osf.io/{project._id}/analytics/'},
)
resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=reader.auth)
assert resp.status_code == 204
assert mock_save.call_count == 0

def test_non_contributor_pageview_recorded(self, app, mock_save):
creator = AuthUserFactory()
visitor = AuthUserFactory()
project = ProjectFactory(creator=creator, is_public=True)
payload = counted_usage_payload(
item_guid=project._id,
action_labels=['view', 'web'],
pageview_info={'page_url': f'https://osf.io/{project._id}/'},
)
resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=visitor.auth)
assert resp.status_code == 201
assert mock_save.call_count == 1

def test_parent_contributor_not_on_child_component_pageview_recorded(self, app, mock_save):
creator = AuthUserFactory()
child_owner = AuthUserFactory()
parent_reader = AuthUserFactory()
parent = ProjectFactory(creator=creator, is_public=True)
child = NodeFactory(parent=parent, creator=child_owner, is_public=True)
parent.add_contributor(parent_reader, permissions=READ, auth=Auth(creator))
assert not child.contributors_and_group_members.filter(guids___id=parent_reader._id).exists()
payload = counted_usage_payload(
item_guid=child._id,
action_labels=['view', 'web'],
pageview_info={'page_url': f'https://osf.io/{child._id}/'},
)
resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=parent_reader.auth)
assert resp.status_code == 201
assert mock_save.call_count == 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for a user using a View Only Link to make sure they're counted? Also one for if a user is an admin on a parent project but is not a contributor on the component (like your read contributor one above, but for Admin). For the admin one, I'm not sure that we want to change it whichever way it works out, but I would like to know what to expect there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants