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

@gaws/gaws

v0.1.1

Published

[![npm](https://img.shields.io/npm/v/@gaws/core.svg)](https://npm.im/@gaws/gaws) [![npm](https://img.shields.io/npm/l/@gaws/core.svg)](https://npm.im/@gaws/gaws) [![npm](https://img.shields.io/npm/dm/@gaws/core.svg)](https://npm.im/@gaws/gaws)

Downloads

4

Readme

GAWS

TypeScript modules for writing powerful AdWords Scripts quickly & efficiently

npm npm npm

Table of Contents

Installation

npm install @gaws/gaws

Getting Started

The quickest way to get started is to clone the starter repo. The starter uses Rollup to build the bundle. One of rollup's features is tree shaking. Any functions that are not called will be removed from the bundled output. AdWords Scripts require a "main" function to run. To keep this function in your bundled output, you will need to call it. The easiest way to do this is to use an Immediately Invoked Function Expression (IIFE). e.g.

(function main(){

  // your code...
  
})();

But, in some cases, IIFEs can cause a script to miss iterations. So, the safest way to make sure you function remains in your bundled output is to call it then remove the call when you move your script to AdWords.

function main(){

  // your code

}

main(); // remove this from your bundled output

Usage

Iterators

An iterator takes as an input an object containing the following AdWords selectors as properties:

  • entity: any AdWords entity i.e. AdWordsApp.keywords(), AdWordsApp.campaigns(), etc.
  • conditions: an array of conditions i.e. ['Impressions > 100','Clicks > 0']
  • dateRange: either an AdWords date string or object
  • order: specifies the ordering of the returned entities
  • ids: adds a collection of IDs as a condition
  • limit: limits the number of returned entities to the specified value

Only the entity property is required. More information on valid inputs for conditions, date ranges, order values and ids can be found here.

Methods available for Iterators mirror the following native JavaScript Array methods:

  • every
  • filter
  • find
  • findIndex
  • forEach
  • map
  • reduce
  • slice
  • some

The length property is also available. The following is a very basic example which logs the name of each ad group with at least 100 impressions over the last 7 days:

import { Iterator } from '@gaws/core'

function main() {
    const iterator = new Iterator({
        entity: AdWordsApp.adGroups(),
        conditions: ['Impressions > 100'],
        dateRange: 'LAST_7_DAYS'
    })

    iterator.forEach(group => Logger.log(group.getName()))
}
main() 

Reports

Documentation coming soon. They are very similar to Iterators. The underlying method logic is the same.

HTML

You can create and import HTML templates for emails (or any other use) and interpolate values similar to handlebars, mustache, etc. Let's set up two html templates and a css file:

<!-- template.html -->
<!doctype html>
<html>
    <head>
        <style>
            {{ style }}
        </style>
    </head>
    <body>
        <table>
            <thead>
                <td>AdGroup</td>
                <td>Clicks</td>
                <td>Impressions</td>
                <td>Conversions</td>
            </thead>
            <tbody>
                {{ rows }}
            </tbody>
        </table>
    </body>
</html>

<!-- row.html -->
<tr>
    <td>{{ name }}</td>
    <td>{{ clicks }}</td>
    <td>{{ impressions }}</td>
    <td>{{ conversions }}</td>
</tr>
/* styles.css */
table {
    color: blue
}

You can use the following script to fill out your template and send an email with every ad group that has at least one click in the last 7 days:

import { Iterator } from '@gaws/core'
import { Template } from '@gaws/html'
import template from './template.html'
import row from './row.html'
import styles from './styles.css'

const dateRange = 'LAST_7_DAYS'

function main() {
    
    const cells = new Iterator({
        entity: AdWordsApp.adGroups(),
        conditions: ['Clicks > 0'],
        dateRange: dateRange
    }).reduce((str, group) => {
        const stats = group.getStatsFor(dateRange)
        return str + new Template(row).render({
            name: group.getName(),
            clicks: stats.getClicks(),
            impressions: stats.getImpressions(),
            conversions: stats.getConversions()
        })
    }, '')

    const html = new Template(template).render({
        style: styles,
        rows: cells
    })
    
    MailApp.sendEmail({
        to: '[email protected]',
        subject: 'testing',
        htmlBody: html
    })
}
main()