Skip to content

A starter project for Google Ads Scripts using Typescript

License

Notifications You must be signed in to change notification settings

JJPell/GoogleAdsScriptsStarter

Repository files navigation

Google Ads Scripts Starter Project 😎

This is a starter(template, bare-bones, skeleton) project for Google Ads Scripts. The aim for this starter project was to improve the developer experience when coding for the Google Ads Scripts environment. It allows you to create scripts using modern ES6+ JavaScript and TypeScript syntax while still being able to build and run your script on the outdated Google Ads Scripts Rhino Engine (ES3) runtime.

Some of the key advantages of using this project are:

  • Compilation of multiple files.
  • Easily import, use and build external npm packages in to your script.
  • TypeScript.
  • Google Ads Scripts custom types.
  • JavaScript ES6+ features.
  • Builds into a single ES3 JavaScript build file.

⚙ Getting Started

Once you have cloned this repository and ran npm install all that is required to do the following to build and deploy your script.

  1. Run the npm run build
  2. Copy and paste the compiled JavaScript file within the build folder to your google ads script.

Simple!

⭐ GoogleAdsScript Types

The standard google ads scripts global variables are automatically available within the global scope, the same as they are within a normal google ads script. This means that you can reference AdsApp and AdsManagerApp globally and if you're using TypeScript the types for variables set to method calls from these added and checked implicitly.

To reference any of the google ads scripts types within the project, you can do so using the GoogleAdsScripts namespace. You will find all the types nested under this, and in the same structure as the Google Ads Scripts documentation website, where things are nested under either AdsApp or AdsManagerApp.

Just a few of these types and where to find them:

Entity Type
Account GoogleAdsScripts.AdsApp.Account
Campaign GoogleAdsScripts.AdsApp.Campaign
ManagedAccount GoogleAdsScripts.AdsManagerApp.ManagedAccount

An example of using the AdGroup type as a function parameter:

function doSomethingToAdGroup(adGroup: GoogleAdsScripts.AdsApp.AdGroup): void {
  // ...
}

To shorten the type name you can do the following:

type AdGroup = GoogleAdsScripts.AdsApp.AdGroup;

function doSomethingToAdGroup(adGroup: AdGroup): void {
  // ...
}

🚀 Examples

To use an example simply replace the code within src/main.ts with the example code.

📦 External Packages

You cannot use external packages that require either node.js or browser environment dependencies. A good rule of thumb is to look at the number of dependencies listed on the npm web page for the package.