npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@anthnyalxndr/gtm-client

v1.1.0

Published

Authenticated, throttled Google Tag Manager API v2 client: OAuth with a shared credential directory, retry with backoff, and typed helpers for accounts and containers.

Downloads

363

Readme

@anthnyalxndr/gtm-client

An authenticated, throttled client for the Google Tag Manager API v2, built on Google's per-API @googleapis/tagmanager package. Use it from any project that needs to call Tag Manager from TypeScript or Node.

pnpm add @anthnyalxndr/gtm-client

What it does

  • OAuth once, everywhere. Client secrets and the token live in ~/.config/gtm-apply/ (override with GTM_APPLY_CONFIG_DIR, or pass paths to the constructor). First run opens a browser and stores the token; every later run on the machine reuses it. A revoked token produces an error that names the file to delete.
  • Throttle and retry. client.call(fn) serializes requests with a minimum gap and retries 429 and 5xx with backoff. Every helper goes through it.
  • The raw service. client.service is the generated tagmanager_v2.Tagmanager instance for anything not wrapped.
  • Typed helpers. listAccounts, resolveContainer (find a container by its GTM-XXXXXXX public id across every account you can see), createContainer.
  • A fake for tests. @anthnyalxndr/gtm-client/testing exports createFakeService, an in-memory implementation of the API surface with workspace, version, and fingerprint semantics, so code built on the client can be tested without credentials.

Usage

import { GtmClient, listAccounts, resolveContainer } from "@anthnyalxndr/gtm-client";

const client = new GtmClient();
await client.init();

for (const account of await listAccounts(client)) {
  console.log(account.accountId, account.name);
}

const ref = await resolveContainer(client, "GTM-XXXXXXX");
const tags = await client.call(() =>
  client.service.accounts.containers.workspaces.tags.list({
    parent: `${ref.path}/workspaces/1`,
  })
);

Testing with the fake

import { GtmClient } from "@anthnyalxndr/gtm-client";
import { createFakeService } from "@anthnyalxndr/gtm-client/testing";

const { service, state } = createFakeService();
const client = new GtmClient({ service, minIntervalMs: 0 });
// state.calls records every method invoked; state.versions holds snapshots.

Credentials file

Create an OAuth client of type "Desktop app" in Google Cloud, download the JSON, and save it as ~/.config/gtm-apply/client_secrets.json. The token is written next to it on first run.

License

Apache-2.0