Get top ranking analytic data for a Gateway

Usage

import { PinataSDK } from "pinata-web3";

const pinata = new PinataSDK({
  pinataJwt: process.env.PINATA_JWT!,
  pinataGateway: "example-gateway.mypinata.cloud",
});

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "cid"
})
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng");

Returns

export type TopGatewayAnalyticsItem = {
	value: string;
	requests: number;
	bandwidth: number;
};

Parameters

Filter response with the following additional methods.

domain

  • Type: string

Domain of the Gateway to get analytics for. Must be owned by the same account that is being authorized.

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud"
})

start

  • Type: string

Start date for the analytics query in the format YYYY-MM-DD

const analytics = await pinata.gateways.topUsageAnalytics({
  start: "2024-08-01"
})

end

  • Type: string

End date for the analytics query in the format YYYY-MM-DD

const analytics = await pinata.gateways.topUsageAnalytics({
  end: "2024-08-15"
})

sortBy

  • Type: requests | bandwidth

Sort results by either requests or bandwidth

const analytics = await pinata.gateways.topUsageAnalytics({
  sortBy: "requests"
})

attribute

  • Type: cid | country | region | user_agent | referer | file_name

Target attribute to aggregate results with

const analytics = await pinata.gateways.topUsageAnalytics({
  attribute: "cid"
})

cid (Optional)

  • Type: string

Filter results by CID

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "cid"
})
.cid("QmVLwvmGehsrNEvhcCnnsw5RQNseohgEkFNN1848zNzdng");

fileName (Optional)

  • Type: string

Filter results by file name

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "file_name"
})
.fileName("pinnie.png");

userAgent (Optional)

  • Type: string

Filter results by a target user agent

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "user_agent"
})
.userAgent("Go-http-client/2.0");

country (Optional)

  • Type: string

Filter results by country

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "country"
})
.country("us");

region (Optional)

  • Type: string

Filter results by a target region with the format lowercaseCountry - upperCaseRegion

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "country"
})
.region("us - TN");

referer (Optional)

  • Type: string

Filter results by a target referer

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "referer"
})
.referer("https://docs.pinata.cloud");

limit (Optional)

  • Type: number

Limit the number of results, default is 100

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "referer"
})
.limit(100);

sort (Optional)

  • Type: asc | desc

Sort the result values by either asc or desc

const analytics = await pinata.gateways.topUsageAnalytics({
  domain: "docs.mypinata.cloud",
  start: "2024-08-01",
  end: "2024-08-15",
  sortBy: "requests",
  attribute: "referer"
})
.sort("asc")