Overview
TikTok analytics inside the app are limited and reset frequently. This workflow runs every Sunday evening, pulls your recent posts via the Scavio TikTok API, calculates weekly performance metrics (views, likes, comments, shares, engagement rate), identifies your top and bottom performers, and exports a structured report. Use it to spot which content formats work, when your audience is most active, and what to double down on next week. One weekly run costs about 2-3 credits ($0.01-$0.015).
Trigger
Cron Sunday 8 PM UTC
Schedule
Weekly Sunday 8 PM
Workflow Steps
Fetch Recent Posts
Call Scavio TikTok API to retrieve all posts published in the past 7 days for your account.
Calculate Performance Metrics
Compute total and average views, likes, comments, shares, and engagement rate for the week.
Rank Content Performance
Sort posts by engagement rate and views to identify top 3 and bottom 3 performers.
Compare Against Prior Week
Load last week's report and compute week-over-week deltas for all key metrics.
Export Weekly Report
Write a structured JSON report with metrics, rankings, and recommendations.
Python Implementation
import requests, os, json
from pathlib import Path
from datetime import date, timedelta
API_KEY = os.environ["SCAVIO_API_KEY"]
TH = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
USERNAME = "your_tiktok_username"
REPORTS_DIR = Path("tiktok_reports")
REPORTS_DIR.mkdir(exist_ok=True)
def fetch_user_posts(username: str) -> list:
resp = requests.post(
"https://api.scavio.dev/api/v1/tiktok/user/posts",
headers=TH,
json={"username": username},
timeout=15,
)
resp.raise_for_status()
return resp.json().get("posts", [])
def calculate_metrics(posts: list) -> dict:
if not posts:
return {"total_views": 0, "total_likes": 0, "avg_engagement": 0}
total_views = sum(p.get("views", 0) for p in posts)
total_likes = sum(p.get("likes", 0) for p in posts)
total_comments = sum(p.get("comments", 0) for p in posts)
total_shares = sum(p.get("shares", 0) for p in posts)
avg_engagement = (total_likes + total_comments) / max(total_views, 1) * 100
return {
"post_count": len(posts),
"total_views": total_views,
"total_likes": total_likes,
"total_comments": total_comments,
"total_shares": total_shares,
"avg_engagement_rate": round(avg_engagement, 2),
}
def run_review():
posts = fetch_user_posts(USERNAME)
metrics = calculate_metrics(posts)
ranked = sorted(posts, key=lambda p: p.get("likes", 0) + p.get("comments", 0), reverse=True)
top_3 = [{"url": p.get("url", ""), "likes": p.get("likes", 0), "views": p.get("views", 0)} for p in ranked[:3]]
bottom_3 = [{"url": p.get("url", ""), "likes": p.get("likes", 0), "views": p.get("views", 0)} for p in ranked[-3:]]
prev_file = REPORTS_DIR / f"report_{date.today() - timedelta(days=7)}.json"
wow_delta = {}
if prev_file.exists():
prev = json.loads(prev_file.read_text())
for key in ["total_views", "total_likes", "total_comments"]:
prev_val = prev.get("metrics", {}).get(key, 0)
wow_delta[key] = metrics[key] - prev_val
report = {"date": str(date.today()), "metrics": metrics, "top_3": top_3, "bottom_3": bottom_3, "wow_delta": wow_delta}
out = REPORTS_DIR / f"report_{date.today()}.json"
out.write_text(json.dumps(report, indent=2))
print(f"Weekly review: {metrics['post_count']} posts, {metrics['total_views']} views, {metrics['avg_engagement_rate']}% engagement")
return report
run_review()JavaScript Implementation
const TH = {'Authorization': 'Bearer '+process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
const fs = await import('fs');
const USERNAME = 'your_tiktok_username';
const REPORTS_DIR = 'tiktok_reports';
try { fs.mkdirSync(REPORTS_DIR); } catch {}
async function fetchUserPosts(username) {
const r = await fetch('https://api.scavio.dev/api/v1/tiktok/user/posts', {method:'POST', headers:TH, body:JSON.stringify({username})});
return (await r.json()).posts || [];
}
const posts = await fetchUserPosts(USERNAME);
const totalViews = posts.reduce((s,p)=>s+(p.views||0),0);
const totalLikes = posts.reduce((s,p)=>s+(p.likes||0),0);
const totalComments = posts.reduce((s,p)=>s+(p.comments||0),0);
const totalShares = posts.reduce((s,p)=>s+(p.shares||0),0);
const avgEngagement = totalViews > 0 ? Math.round((totalLikes+totalComments)/totalViews*10000)/100 : 0;
const metrics = {postCount:posts.length, totalViews, totalLikes, totalComments, totalShares, avgEngagementRate:avgEngagement};
const ranked = [...posts].sort((a,b)=>(b.likes||0)+(b.comments||0)-(a.likes||0)-(a.comments||0));
const top3 = ranked.slice(0,3).map(p=>({url:p.url||'', likes:p.likes||0, views:p.views||0}));
const bottom3 = ranked.slice(-3).map(p=>({url:p.url||'', likes:p.likes||0, views:p.views||0}));
const today = new Date().toISOString().split('T')[0];
const prevDate = new Date(Date.now()-7*86400000).toISOString().split('T')[0];
let wowDelta = {};
try {
const prev = JSON.parse(fs.readFileSync(REPORTS_DIR+'/report_'+prevDate+'.json', 'utf8'));
wowDelta = {totalViews: totalViews-(prev.metrics.totalViews||0), totalLikes: totalLikes-(prev.metrics.totalLikes||0)};
} catch {}
const report = {date:today, metrics, top3, bottom3, wowDelta};
fs.writeFileSync(REPORTS_DIR+'/report_'+today+'.json', JSON.stringify(report, null, 2));
console.log('Weekly review: '+metrics.postCount+' posts, '+metrics.totalViews+' views, '+metrics.avgEngagementRate+'% engagement');Platforms Used
TikTok
Trending video, creator, and product discovery