Problem/Motivation

I am writing a module that helps module maintainers keep track of the usage of their modules. The data source that I have been able to find is this:

https://www.drupal.org/jsonapi/index/project_modules?filter%5Bmachine_na...

The response has the following properties/values inside "data" > "attributes":

  "field_active_installs": "{\"8.x-3.x\":1671,\"8.x-4.x\":2,\"5.0.x\":2709,\"5.1.x\":7914}"
  "field_active_installs_total": 12296,

However, as far as I can tell, it doesn't provide a way to get historical data about project usage, as you can see on the https://www.drupal.org/project/usage/charts page.

Steps to reproduce

See above.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupalorg-3560293

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andileco created an issue. See original summary.

fjgarlin’s picture

This was a conscious decision introduced in #3498849: Project usage totals should exclude Drupal 7 branches.

andileco’s picture

Sorry, I didn't mean any D7, just more than a single entry for 5.1.x, for example.

fjgarlin’s picture

Single entry for specific releases is not an option, but you can parse the field and store it as you need:

"field_active_installs": "{\"8.x-3.x\":1671,\"8.x-4.x\":2,\"5.0.x\":2709,\"5.1.x\":7914}"

For example:

// [data > attributes > field_active_installs]
$field = "{\"8.x-3.x\":1671,\"8.x-4.x\":2,\"5.0.x\":2709,\"5.1.x\":7914}";
$usage = json_decode($field);
foreach ($usage as $branch => $total) {
	echo "Branch: " . $branch . " // Total: " . $total . PHP_EOL;
}

Produces:

Branch: 8.x-3.x // Total: 1671
Branch: 8.x-4.x // Total: 2
Branch: 5.0.x // Total: 2709
Branch: 5.1.x // Total: 7914
fjgarlin’s picture

Sorry, I get what you are asking now.

You mean weekly data for each branch. That information is not stored as part of the entity itself, it has a separate table.
I guess we could do something like #3559622: Provide way to access all projects maintained by a user, where we create a new endpoint with custom parameters.

fjgarlin’s picture

Status: Active » Needs work

I've put some WIP I've been experimenting with just to see if we can reuse some code. I will continue work on it in the coming days.

This will also conflict with the other mentioned issue, so I will fix that once the other is deployed/merged.

fjgarlin’s picture

Status: Needs work » Needs review

I'm happy with the logic here to be reviewed, but as mentioned before, this #3559622: Provide way to access all projects maintained by a user should go first, and I will fix the conflict once merged.

The endpoint will be something like /drupalorg-api/project-usage?nid=3060[&weeks_ago=10]
If no "weeks_ago" param is given, it will be all-time data.

The output will be split by weekly timestamps:

{
  "usage": {
    "timestamp1": {
      "5.x-1.x": 159454,
      "6.x-2.x": 50834,
      "7.x-1.x": 15643,
      "6.x-3.x": 51159
    },
    "timestamp2": {
      "5.x-1.x": 15947,
      "6.x-2.x": 5038,
      "7.x-1.x": 1545,
      "6.x-3.x": 5110
    }
  },
  "success": true
}
fjgarlin’s picture

Feedback addressed.

Either this or #3559622: Provide way to access all projects maintained by a user can go first and then I'll adapt the other. I don't think it really matters the order, so if this one is ready before it can be merged.

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

  • fjgarlin committed 173eb0e5 on 1.0.x
    feat: #3560293 Expose historical project usage statistics via the API...
fjgarlin’s picture

Status: Reviewed & tested by the community » Fixed

This is now merged. It will be deployed today.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

fjgarlin’s picture

Deployed.

Example, webform usage for the last year: https://new.drupal.org/drupalorg-api/project-usage?nid=7404&weeks_ago=53

Note that querying all time data for big modules might incur in timeouts when accessed via web (5xx errors).

andileco’s picture

Status: Fixed » Needs work

@fjgarlin, I believe there is a data issue with this. I went to look at Charts: https://new.drupal.org/drupalorg-api/project-usage?nid=232629&weeks_ago=2

Here were the results for me:

{
  "usage": {
    "1763251200": {
      "6.x-1.x": 1148,
      "7.x-1.x": 106,
      "7.x-2.x": 253545,
      "8.x-3.x": 45540,
      "8.x-4.x": 68,
      "5.0.x": 47075,
      "5.1.x": 22058
    },
    "1763856000": {
      "6.x-1.x": 1096,
      "7.x-1.x": 159,
      "7.x-2.x": 251146,
      "8.x-3.x": 44304,
      "8.x-4.x": 68,
      "5.0.x": 44205,
      "5.1.x": 21488
    }
  },
  "success": true
}

The results here (https://www.drupal.org/project/usage/charts) are:

Week 6.x-0.x 6.x-1.x 7.x-1.x 7.x-2.x 8.x-1.x 8.x-3.x 8.x-4.x 5.0.x 5.1.x Total
November 23, 2025 0 21 3 6,162 0 1,612 2 2,552 8,308 18,660
November 16, 2025 0 22 2 6,226 0 1,665 2 2,815 8,236 18,968

Thank you!

fjgarlin’s picture

True! Thanks for reporting. I took some of the logic for the individual weekly jobs, but it was multidimensional arrays, so I'm sure that I forgot to reset something somewhere. Looking into this.

fjgarlin’s picture

Found the issue! We were literally looping the loop on numbers!

Commit: https://git.drupalcode.org/project/drupalorg/-/commit/eadec4681ee355fcab...

Deploying shortly.

fjgarlin’s picture

Status: Needs work » Fixed

Numbers here https://new.drupal.org/drupalorg-api/project-usage?nid=232629&weeks_ago=2 match exactly what we see in comment #15.

{
    "usage": {
        "1763251200": {
            "6.x-1.x": 22,
            "7.x-1.x": 2,
            "7.x-2.x": 6226,
            "8.x-3.x": 1665,
            "8.x-4.x": 2,
            "5.0.x": 2815,
            "5.1.x": 8236
        },
        "1763856000": {
            "6.x-1.x": 21,
            "7.x-1.x": 3,
            "7.x-2.x": 6162,
            "8.x-3.x": 1612,
            "8.x-4.x": 2,
            "5.0.x": 2552,
            "5.1.x": 8308
        }
    },
    "success": true
}

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • fjgarlin committed 173eb0e5 on docs-as-code
    feat: #3560293 Expose historical project usage statistics via the API...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.