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

ads.txt

v0.4.0

Published

Ads.txt parser

Downloads

6,537

Readme

ads.txt

Ads.txt parser and generator

Build Status npm version

Parse ads.txt file contents, according to the IAB OpenRTB Ads.txt Public Spec. Generate ads.txt files from a sensible manifest structure.

Note: There may be some minor descrepencies between this implementation and the spec, but the ads.txt package does aim to be 100% in-line with the spec. Please file an issue if you notice any problems!

About

Ads.txt files are used by publishers to list their advertising partners that run ads on their sites. For instance, this is the top section of the ads.txt file on cnn.com:

 # CNN.com/ads.txt
 # 
 # DOMESTIC
google.com, pub-7439281311086140, DIRECT, f08c47fec0942fa0 # banner, video, native
rubiconproject.com, 11078, DIRECT, 0bfd66d529a55807 # banner, video
c.amazon-adsystem.com, 3159, DIRECT # banner, video
openx.com, 537153334, DIRECT # banner
appnexus.com, 7745, DIRECT # banner, video
kargo.com, 105, DIRECT # banner

Installation

Simply npm install the package:

npm install ads.txt --save

Usage

Parsing

Import the parsing method and pass the contents of an ads.txt file to it:

const { parseAdsTxt } = require("ads.txt");

const { variables, fields } = parseAdsTxt(someAdsTxtContent);

parseAdsTxt outputs an object with variables (Object) and fields (Array).

variables may resemble the following:

{
    "subdomain": ["divisionone.example.com", "divisiontwo.example.com"],
    "contact": "Jane Doe"
}

Each field item in the fields array corresponds with a parsed ads.txt line:

{
    "domain": "openx.com",
    "publisherAccountID": "343560932",
    "accountType": "DIRECT",
    "certificateAuthorityID": "38f6ae102b"
}

Fields can also handle comments, if they are present in a parsed ads.txt file. For instance, the line kargo.com, 105, DIRECT # banner would generate the following field:

{
    "domain": "kargo.com",
    "publisherAccountID": "105",
    "accountType": "DIRECT",
    "comment": "banner"
}

The parseAdsText function takes an options object (parseAdsTxt(contents, options)) that takes the following properties:

| Property | Range | Default | Description | |---------------------|--------------------|--------------|-------------------------------------------------------------------------| | invalidLineAction | "filter" / "throw" | "filter" | Action to take when an invalid line is found. "throw" throws an exception, "filter" removes the line and continues on. |

The parsing process will recognise both CR (Linux/Mac) and CRLF (Windows) when reading ads.txt content.

Generating

Ads.txt files can also be generated by using the generateAdsTxt method:

const { generateAdsTxt } = require("ads.txt");

const adsTxtContent = generateAdsTxt({
    fields: [
        {
            "domain": "openx.com",
            "publisherAccountID": "343560932",
            "accountType": "DIRECT",
            "certificateAuthorityID": "38f6ae102b"
        },
        {
            "domain": "appnexus.com",
            "publisherAccountID": "455492434",
            "accountType": "DIRECT",
            "certificateAuthorityID": "90a23bf11ac",
            "comment": "banner"
        }
    ],
    variables: {
        CONTACT: "John Doe",
        SUBDOMAIN: ["sub1.domain.com", "sub2.domain.com"]
    }
});

The generation method uses the following syntax: generateAdsTxt(manifest[, header[, footer]]). A header and/or footer can be added to the generated document:

const adsTxtContent = generateAdsTxt(manifest, "My Website\nwebsite.com");

This example might generate the following:

# My Website
# website.com
openx.com, 537153334, DIRECT

Both header and footer are optional.