Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dmgt/google-ad-manager-api

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dmgt/google-ad-manager-api

Typed Google Ad Manager API

  • 8.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
499
decreased by-0.6%
Maintainers
1
Weekly downloads
 
Created
Source

@dmgt/google-ad-manager-api

A fully typed library to access Google's Ad Manager.

Installation

npm install google-auth-library @dmgt/google-ad-manager-api

Usage

Simple queries

import {
  GoogleAdManager,
  In,
  Not,
  Like,
  getByStatement,
} from '@dmgt/google-ad-manager-api'
import { JWT } from 'google-auth-lbrary'

const jwt = new JWT({
  key: 'MY_JWT_KEY',
  email: 'MY_JWT_EMAIL',
  scopes: ['https://www.googleapis.com/auth/dfp'],
})

const api = new GoogleAdManager({
  applicationName: 'MY_APPLICATION_NAME',
  networkCode: 123456789,
  authorize: () => jwt.authorize(),
})

const client = await api.createLineItemServiceClient()

const [response] = await getByStatement(client, 'lineItems', {
  limit: 10,
  where: {
    orderId: In(1, 2, 3),
    id: Not(11222),
    name: Like('foo %'),
    orderName: 'Foo',
  },
})

expect(response.rval?.results).toHaveLength(10)

The following will produce the same result albeit more verbose:

import {
  LineItemService,
  In,
  Not,
  Like,
  pql,
} from '@dmgt/google-ad-manager-api'

const [response] = await client.getLineItemsByStatementAsync({
  filterStatement: {
    query: pql<LineItemService.LineItems>({
      limit: 10,
      where: {
        orderId: In(1, 2, 3),
        id: Not(11222),
        name: Like('foo %'),
        orderName: 'Foo',
      },
    }),
  },
})

You can also type the pql function with JSDocs:

/**
 * @typedef {import('@dmgt/google-ad-manager-api').PQL<
 *   import('@dmgt/google-ad-manager-api').LineItemService.LineItems
 * >} LineItemsPQL
 */

const [response] = await client.getLineItemsByStatementAsync({
  filterStatement: {
    query: /** @type {LineItemsPQL} */ (pql)({
      limit: 10,
      where: {
        orderId: In(1, 2, 3),
        id: Not(11222),
        name: Like('foo %'),
        orderName: 'Foo',
      },
    }),
  },
})

Paginated queries

When quering large amounts of data, you'd generally want to use GAM's pagination feature. Use the iterate function to help iterate through all individual items in paginated queries.

import {
  GoogleAdManager,
  iterate,
  getByStatement,
} from '@dmgt/google-ad-manager-api'
import { JWT } from 'google-auth-lbrary'

const jwt = new JWT({
  key: 'MY_JWT_KEY',
  email: 'MY_JWT_EMAIL',
  scopes: ['https://www.googleapis.com/auth/dfp'],
})

const api = new GoogleAdManager({
  applicationName: 'MY_APPLICATION_NAME',
  networkCode: 123456789,
  authorize: () => jwt.authorize(),
})

const client = await api.createLineItemServiceClient()

for await (const result of iterate({
  executeQuery: (limit, offset) =>
    getByStatement(client, 'lineItems', {
      limit,
      offset,
    }),
})) {
  console.info(result)
}

Keywords

FAQs

Package last updated on 22 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc