Guides

Profile Statistics

Query profile statistics from across the protocol.

The Profile type contains a stats field which includes total counts for different statistics. These statistics are calculated by aggregating the data from all the publications, mirrors, quotes, reactions and comments that a profile has made across the protocol.

Each individual statistic can be queried using a set of filters to allow for the result to be tailored to specific use-cases.

These fields are available on all methods that contain Profile types in their response but here we will explore this in detail.

Request

You need to specify the arguments for each statistic at a field level, passing the arguments directly to each field.

If you're using the LensClient, if you specify the arguments in the optional options parameter - the cascading down to each field is handled for you. If you're using GraphQL, you need to pass the arguments to each field.

The LensClient also provides default arguments for each statistic that is derived from values in the LensConfig, these can be overridden at an individual method level if required.

ProfileStatsArg

  • forApps: AppId[] (optional)
    • The apps to filter the statistics by. AppId is of type string.
  • customFilters: CustomFiltersType[] (optional)
    • The custom filters to apply to the statistics. CustomFiltersType is of type enum.

Used for the following fields:

  • followers
  • following
  • comments
  • posts
  • mirrors
  • quotes
  • publications

ProfileStatsReactionArgs

  • type: PublicationReactionType (required)
    • The type of reaction to filter by. Can be UPVOTE or DOWNVOTE PublicationReactionType is of type enum.

Used for reactions.

ProfileStatsCountOpenActionArgs

  • anyOf: OpenActionFilter[] (optional)
    • The open action filters to apply to the statistics.

Used for countOpenActions.

Invocation

const result = await client.profile.fetch(
  { forProfileId: '0x01' },
);
query Profile {
  profile(request: { profileId: "PROFILE_ID" }) {
    stats(request: { forApps: ["APP_ID"] }) {
      followers(request: { forApps: ["APP_ID"] })
      following(request: { forApps: ["APP_ID"] })
      comments(request: { forApps: ["APP_ID"] })
      posts(request: { forApps: ["APP_ID"] })
      mirrors(request: { forApps: ["APP_ID"] })
      quotes(request: { forApps: ["APP_ID"] })
      mirrors(request: { forApps: ["APP_ID"] })
      quotes(request: { forApps: ["APP_ID"] })
      publications(request: { forApps: ["APP_ID"] })
      upvoteReactions: reactions(request: { type: UPVOTE })
      downvoteReactions: reactions(request: { type: DOWNVOTE })
      countOpenActions(request: { anyOf: [] })
    }
  }
}

Response

{
  // all other profile fields
  "stats": {
    "followers": 0,
    "following": 0,
    "comments": 0,
    "posts": 0,
    "mirrors": 0,
    "quotes": 0,
    "publications": 0,
    "upvoteReactions": 0, // note that we aliased reactions to upvoteReactions in the query
    "downvoteReactions": 0, // note that we aliased reactions to downvoteReactions in the query
    "countOpenActions": 0
  }
}

Full LensClient Example

// your LensClient does not need to be authenticated

// stats across the whole protocol
const protocolWideStats = await client.profile.fetch(
  { forProfileId: '0x01' },
);

// filter open actions
const filteredOpenActions = await client.profile.fetch(
  { forProfileId: '0x01' },
  {
    profileStatsCountOpenActionArgs: {
      anyOf: [
        {
          address: modules.items[0].contract.address,
        },
        {
          category: OpenActionCategoryType.Collect,
        },
      ] as OpenActionFilter[],
    },
  },
);