Google Ads Scripts generally follow this layout:
Any script you find online should begin with comment indicating the license and copyright. For Google Ads scripts, these are virtually always free MIT or Apache licenses, which allow you to change and use the script for any (including commercial) purpose as long as you keep the copyright/license in tact when you use the script and do not try to sell the script itself.
The license is followed by a comment block with information about the script, including the script author, version, and a description of what it does. Sometimes the description will also include usage instructions, or a link to more detailed documentation.
The first actual code in the script will be a set of variables named all uppercase letters. These are the configuration settings for the script. There may be many or just one.
A comment above each setting describes of how it affects script functionality (and instructions for determining or obtaining the proper value, if it’s not straightforward). If there is no comment for a setting, chances are, it’s not something you should mess with!
Required settings are generally listed first and have placeholder values such as: “
INSERT_SPREADSHEET_URL_HERE“. Optional settings are either blank or have default values.
In many cases, the defaults for optional settings are optimal values for the script. Before dramatically changes any of the defaults, you should test smaller changes incrementally, and observe the impact on script functionality and execution speed.
Everything that follows is the actual script—the code that does what’s described in the description, according to the configured settings. Note, this code can be very long, but most scripts are designed so you’re not required to touch (or even look at) any of it.
Many example scripts will work without much tweaking, but may need to be configured with your own information (i.e. an account id, a Google spreadsheet URL, etc). Configuration settings are the variables named with all-caps, listed after the metadata comment at the top of the script.
The script instructions (either online documentation or in the comments at the top of the script) often indicate which settings you have to update, but it’s a good idea to look at the comment above each variable to make sure none are marked as required.
Even if none are required, you may want to tweak some settings to better suit your needs.
When updating the settings, take care to only change the value. (Note, if the value is surrounded by quotes, those quotes simply delimit the value, and are not part of the value itself.)
Be careful not to:
- Delete quotes surrounding the value
- Delete any semicolons or commas
- Accidentally type any stray characters in the code
- Change the variable name
This is code, so a single missing or unexpected character can break the script. So it may look like improper use of punctuation, but don’t fix it! 🙂
If there is a default or placeholder value, double-click on the value, and only the part that is safe to edit will be selected.
Feel free to leave notes for yourself/others by adding a code comment.
Particularly for optional settings, it’s a good idea to leave a comment with the date, your email, and an explanation of why you changed the setting. It might seem unnecessary, but trust us, later you (or someone else) will be really glad you did.