Here’s how you can use the Dub Python SDK to create a link and retrieve click analytics in timeseries format for it:
Copy
Ask AI
import osimport dubfrom dub.models import operations# Initialize the Dub SDK with your API keyd = dub.Dub( token=os.environ['DUB_API_KEY'], # optional, defaults to DUB_API_KEY)# Create a new linkres = d.links.create(request={ "url": "https://google.com",})print(res.short_link) # e.g. https://dub.sh/abc123# Get analytics for the linkanalytics = d.analytics.retrieve(request={ "link_id": res.id, "interval": "30d", "group_by": "timeseries",})print(analytics) # e.g. [{ "start": "2024-01-01", "clicks": 100 }]