Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up metrics tracking and track download events #1054

Closed
wants to merge 1 commit into from

Conversation

thatbudakguy
Copy link
Member

Closes #1048

cookies[:ahoy_visitor]
end

# Sessions last for 1 hour (default used by Zenodo)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain why zenodo is relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Zenodo tracks view/download metrics and displays them prominently on each item deposited in the repository. It's been basically the main example of a metrics implementation for a repository that we've used since the planning phase of the workcycle.

}
end

# Visitors are remembered for 2 years (Ahoy's default)
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we copying ahoy's defaults? Are we attempting to make this code mimic ahoy?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's an arbitrary choice – I asked Amy if she wanted to choose a different value and she was OK with this one.


private

# We're responsible for ensuring that every event is tied to a visit
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? Can you expand on this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Without this, we aren't able to group events by session. The current specification for the metrics feature is that we want to show "unique" metrics in the same way that Zenodo does – i.e. grouping events by session, so that viewing something repeatedly in a short timeframe gets collapsed into one view. The Visit is the thing we group by to do this.

Visits also host all of the information about the user and their browser. Our requirements don't currently call for using this information, but it seems prudent to collect at least basic information in the event that we later want to examine trends.

Copy link
Member Author

@thatbudakguy thatbudakguy Dec 4, 2023

Choose a reason for hiding this comment

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

To answer the functional side of the "why" question, if you're using ahoy.js, it takes care of visit creation for you. Likewise if you're using the ahoy gem, there's an option to create visits automatically.

Unfortunately, in this situation we aren't doing either one: we need to send events to ahoy's HTTP API (not a local database, like the gem), but we can't send them from the client side. That's also why there are some pieces of ahoy copied here: it's a hybrid of both libraries, but in ruby.

@@ -138,6 +138,22 @@
entries = ZipTricks::FileReader.new.read_zip_structure(io: StringIO.new(response.body))
expect(entries.length).to eq 6
end

context 'when metrics tracking is enabled' do
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be great if this could be made a request spec instead. Controller specs are deprecated

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but is this PR the right place? I just needed to add a single test for the new feature.

@thatbudakguy
Copy link
Member Author

This works as intended in stacks, but it turns out that Ahoy doesn't want to accept requests made from the server to its API – see comments on #1048.

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.

Send download events to the SDR metrics service
2 participants