Skip to content

Commit

Permalink
Resolve breaking Plausible API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbirchard committed Mar 7, 2024
1 parent 4005d39 commit cb7ced4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/analytics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
)
async def migrate_site_analytics():
"""Fetch top searches for weekly & monthly time periods."""
weekly_traffic = top_visited_pages_by_timeframe("7d", limit=100)
monthly_traffic = top_visited_pages_by_timeframe("30d", limit=500)
weekly_traffic = top_visited_pages_by_timeframe("7d", limit=50)
monthly_traffic = top_visited_pages_by_timeframe("30d", limit=100)
LOGGER.success(
f"Inserted {len(weekly_traffic)} rows into `weekly_stats`, {len(monthly_traffic)} into `monthly_stats`."
)
Expand Down
6 changes: 3 additions & 3 deletions app/analytics/plausible.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from log import LOGGER


def top_visited_pages_by_timeframe(time_period: str, limit=30) -> Optional[List[dict]]:
def top_visited_pages_by_timeframe(time_period: str, limit=100) -> Optional[List[dict]]:
"""
Get top visited URLs & enrich with post metadata.
Expand Down Expand Up @@ -47,7 +47,7 @@ def fetch_top_visited_pages(time_period: str, limit=30) -> List[Optional[dict]]:
"period": time_period,
"property": "event:page",
"limit": limit,
"metrics": "visitors,bounce_rate,visitors,pageviews,visit_duration",
"metrics": "visitors,visits,bounce_rate,pageviews,visit_duration",
}
resp = requests.get(
settings.PLAUSIBLE_STATS_ENDPOINT,
Expand Down Expand Up @@ -91,7 +91,7 @@ def filter_results(results_list: List[dict]) -> List[dict]:
for result in results_list
if result is not None
and result.get("pageviews") is not None
and result["pageviews"] > 6
and result["pageviews"] > 4
and "/tag" not in result["page"]
and "/page" not in result["page"]
and "/author" not in result["page"]
Expand Down
2 changes: 1 addition & 1 deletion app/analytics/tests/test_plausible_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def test_fetch_top_visited_urls():
"""Test fetching top visited URLs in current month."""
urls = fetch_top_visited_pages("month")
urls = fetch_top_visited_pages("30d")
assert urls is not None
assert len(urls) > 0
assert urls[0]["page"] is not None
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async-timeout==4.0.3 ; python_version >= "3.10" and python_version < "3.11"
attrs==23.2.0 ; python_version >= "3.10" and python_version < "4.0"
blinker==1.7.0 ; python_version >= "3.10" and python_version < "4.0"
boto==2.49.0 ; python_version >= "3.10" and python_version < "4.0"
botocore==1.34.56 ; python_version >= "3.10" and python_version < "4.0"
botocore==1.34.57 ; python_version >= "3.10" and python_version < "4.0"
cachetools==5.3.3 ; python_version >= "3.10" and python_version < "4.0"
certifi==2024.2.2 ; python_version >= "3.10" and python_version < "4.0"
cffi==1.16.0 ; python_version >= "3.10" and python_version < "4.0"
Expand Down

0 comments on commit cb7ced4

Please sign in to comment.