Skip to content

Commit

Permalink
Fixes URL to get Plausible downloads (#567)
Browse files Browse the repository at this point in the history
* Fixes URL to get downloads

* Adjust the test to match the updated code
  • Loading branch information
hectorcorrea authored Feb 12, 2024
1 parent 91f9e12 commit ec77b50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/models/plausible.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def self.downloads(document_id)

site_id = Rails.configuration.pdc_discovery.plausible_site_id
page = "/discovery/catalog/#{document_id}"
url = "#{PLAUSIBLE_API_URL}/stats/breakdown?site_id=#{site_id}&property=event:props:filename&filters=event:page==#{page}&metrics=visitors,pageviews"
# Notice that the Plausible gem use above in pageviews uses "event:page==..." but when we use the raw API
# we cannot pass "=="
url = "#{PLAUSIBLE_API_URL}/stats/breakdown?site_id=#{site_id}&property=event:props:filename&filters=event:page=#{page}&metrics=visitors,pageviews"
authorization = "Bearer #{ENV['PLAUSIBLE_KEY']}"
response = HTTParty.get(url, headers: { 'Authorization' => authorization })
total_downloads = 0
Expand Down
2 changes: 1 addition & 1 deletion spec/models/plausible_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# rubocop:disable Layout/LineLength
RSpec.describe Plausible do
before do
stub_request(:get, "https://plausible.io/api/v1/stats/breakdown?filters=event:page==/discovery/catalog/88163&metrics=visitors,pageviews&property=event:props:filename&site_id=pdc-discovery-staging.princeton.edu")
stub_request(:get, "https://plausible.io/api/v1/stats/breakdown?filters=event:page=/discovery/catalog/88163&metrics=visitors,pageviews&property=event:props:filename&site_id=pdc-discovery-staging.princeton.edu")
.with(
headers: {
'Accept' => '*/*',
Expand Down

0 comments on commit ec77b50

Please sign in to comment.