Documentation Index
Fetch the complete documentation index at: https://pinata-fix--redirect--docs-to--quickstart.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Get analytics on bandwidth for multiple properties
Usage
The analytics class is unique in that it very flexible, but also can require more queries to be used well. Be sure to real the Parameters in detail to understand how it can be used.
The bandwidth method will sort results by highest number of bandwidth, but will also include requests values.
import { PinataSDK } from "pinata";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "example-gateway.mypinata.cloud",
});
const clicks = await pinata.analytics.bandwidth
.days(30)
.limit(10)
.cid("<CID>")
Returns
What is returned in value will depend on they property or query used. For instance, using cid() will return CIDs, country() will return Countries, etc.
type TopAnalyticsResponse = {
data: TopAnalyticsItem[];
};
type TopAnalyticsItem = {
value: string;
requests: number;
bandwidth: number;
};
Parameters
Filter response with the following additional methods. It does require at least one property, such as cid, fileName, userAgent, country, region, or referrer.
cid
Returns bandwidth for all CIDs
const files = await pinata.analytics.bandwidth
.days(7)
.cid()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.cid("bafkreih5aznjvttude6c3wbvqeebb6rlx5wkbzyppv7garjiubll2ceym4")
fileName
Returns bandwidth for all file names
const files = await pinata.analytics.bandwidth
.days(7)
.fileName()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.fileName("pinnie.png")
userAgent
Returns bandwidth for user agents
const files = await pinata.analytics.bandwidth
.days(7)
.userAgent()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.userAgent(
"Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0"
)
country
Returns bandwidth for countries
const files = await pinata.analytics.bandwidth
.days(7)
.country()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.country("us")
region
Returns bandwidth for regions inside of countries
const files = await pinata.analytics.bandwidth
.days(7)
.region()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.region("us - VA")
referer
Returns bandwidth for referers
const files = await pinata.analytics.bandwidth
.days(7)
.referer()
Filter by passing an argument
const files = await pinata.analytics.bandwidth
.days(7)
.referer("https://docs.pinata.cloud/")
days
Number of days to query. Starts with current date and then goes back by provided number.
const files = await pinata.analytics.bandwidth
.days(7)
.cid()
sort
Order results either ascending or descending by created date
const files = await pinata.analytics.bandwidth
.days(7)
.cid()
.sort("asc")
limit
Limit the number of results
const files = await pinata.analytics.bandwidth
.days(7)
.cid()
.limit(10)
customDates
Custom dates to query using a start and end date with the format YYYY-MM-DD
const files = await pinata.analytics.bandwidth
.customDates("2024-11-01", "2024-11-20")
.cid()
from
Provide an alternate Gateway domain to query instead of the default one found in the Pinata SDK Config
const files = await pinata.analytics.bandwidth
.days(7)
.cid()
.from("example-2.mypinata.cloud")