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 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-adwords-node

v1.0.23

Published

Google Ads API Client Library for Node.js

Downloads

86

Readme

google adwords node

NPM Downloads LICENSE

This is a fork of nodejs-google-adwords.

Special thanks to mrdulin for the great work!

Google Ads API Client Library for Node.js. This library is developed for Google Adwords SOAP + WSDL API (v201809).

OAuth

Replace your GCP OAuth 2.0 client ID and open this link in browser,

https://accounts.google.com/o/oauth2/auth?client_id={Your Client ID}&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords&redirect_uri=urn:ietf:wg:oauth:2.0:oob&access_type=offline&approval_prompt=auto

The OAuth2.0 Client type should be other, not web application

If you use client id which client type is web application, you will get below error:

After finish the oauth workflow, you will get authorization code, for example: 4/0wA_JBMyfVH1ZEqZlAr0sOn_XmdzUrBgCjrpi9fVs9TudrjZUDzuUmU

Using authorization code exchange credentials:

curl \
  -d code=4/MgGqR_qEUkzq95LlP_Am8clUbX8t733PvtoMuZ_xsmAA8NHdjK07xXo \
  -d client_id=<client id> \
  -d client_secret=<client secret> \
  -d redirect_uri=urn:ietf:wg:oauth:2.0:oob \
  -d grant_type=authorization_code https://accounts.google.com/o/oauth2/token

Credentials response:

{
  "access_token": "<Access token>",
  "expires_in": 3600,
  "refresh_token": "<Refresh token>",
  "scope": "https://www.googleapis.com/auth/adwords",
  "token_type": "Bearer"
}

You can revoke your access token from: https://myaccount.google.com/u/0/permissions

Above workflow is only for server-side local development without a front-end(client-side), after you make a front-end application, then you can create a OAuth2.0 Client on GCP with web application type and set up your Authorized JavaScript origins and Authorized redirect URIs like below:

Then, when user perform the oauth workflow, you can confirm the oauth workflow on server-side, and store the refresh_token, access_token and other informations in your database. When user click create campaign button on your front-end application, it will send a HTTP request to your server-side, then, you can get the user's access_token from database, can call google adwords api using this access_token.

Environment variables

ADWORDS_CLIENT_ID=<GCP OAuth 2.0 client ID>
ADWORDS_SECRET=<GCP OAuth 2.0 client secret>
ADWORDS_DEVELOPER_TOKEN=<Google Adwords Developer Token>
ADWORDS_CLIENT_CUSTOMER_ID=153-935-9847
ADWORDS_USER_AGENT=Google Ads API Client Library for Node.js
ADWORDS_REFRESH_TOKEN=<OAuth Refresh Token>

Put above environment variables into .env file for local development.

Usage

Initialize AdwordsService with above environment variables

const adwordsService = new AdWordsService({
  clientCustomerId: credentials.ADWORDS_CLIENT_CUSTOMER_ID,
  developerToken: credentials.ADWORDS_DEVELOPER_TOKEN,
  userAgent: credentials.ADWORDS_USER_AGENT,
  clientId: credentials.ADWORDS_CLIENT_ID,
  clientSecret: credentials.ADWORDS_SECRET,
  credentials: {
    refresh_token: credentials.ADWORDS_REFRESH_TOKEN,
  },
});

Get budgets by page:

async function getByPage() {
  const budgetService = adwordsService.getService('BudgetService');
  const paging: IPaging = {
    startIndex: 0,
    numberResults: 2,
  };
  return await budgetService.getByPage(paging);
}

Create a budget:

async function createBudget() {
  const budgetService = adwordsService.getService('BudgetService');

  const budget: IBudget = {
    name: faker.lorem.word(),
    amount: {
      microAmount: BudgetService.UNIT,
    },
    deliveryMethod: Budget.BudgetDeliveryMethod.STANDARD,
    isExplicitlyShared: false,
    status: Budget.BudgetStatus.ENABLED,
  };

  return await budgetService.add(budget);
}

Get campaigns by page:

async function getCampaignsByPages() {
  const paging: IPaging = {
    startIndex: 0,
    numberResults: 1,
  };
  return await campaignService.getByPage(paging);
}

Same usage for other Google Adwords resources

TODO

References