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 🙏

© 2026 – Pkg Stats / Ryan Hefner

puppeteer-datalayer

v1.0.2

Published

puppeteer-datalayer is a node.js module to facilitate interaction with Google Tag Manager's dataLayer in combination with Puppeteer.

Readme

puppeteer-datalayer

puppeteer-datalayer is a node.js module to facilitate interaction with Google Tag Manager's dataLayer in combination with Puppeteer.

What's it for?

puppeteer-datalayer was built with the following two main use cases in mind.

Especially when used with other testing tools like Jest and joi it can be a huge timesaver, because you won't have to spend all your time manually clicking through your site to check if your tracking implementation is doing what it's supposed to.

Frontend Testing

Puppeteer is very useful when doing frontend testing, i. e. checking whether your dataLayer events are trigger properly upon certain user actions on the website, e. g. adding a product to the shopping cart. Checking if the expected event is pushed to dataLayer after mocking the user action is a lot easier with puppeteer-datalayer.

GTM Testing

Make sure your tags in GTM work as expected by pushing predefined events to dataLayer. Afterwards you can listen to network requests in Puppeteer to see if the expected requests (Google Analytics, 3rd party conversion tags, …) were triggered and contain the necessary parameters.

Installation

You can install this package from npm by executing the following command while in your project directory:

npm install puppeteer-datalayer --save

Glossary

To clarify the terminology used in this package:

Message

A message describes any object inside dataLayer regardless of its attributes. These are examples of messages pushed to dataLayer:

dataLayer.push({ event: "addToBasket", product: { id: 12345 } })
dataLayer.push({ order: null })
dataLayer.push({})

Event

An event describes any object inside dataLayer that has an event attribute. An event is always a message but not every message is an event. The name applies no matter whether an event was pushed by a developer-implemented dataLayer.push() or the automatically collected events starting with gtm..

// This is an event
dataLayer.push({ event: "gtm.click" })

// This one, too
dataLayer.push({ event: "addToBasket", product: { id: 12345 } })

// This is not an event, just a message
dataLayer.push({ order: null })

Credits

Special thanks go out to the following people whose content represents the basis this package was built on. Check out their awesome resources:

API

Table of Contents

constructor

Instantiates the dataLayer class

Parameters

  • page string The page object as provided by puppeteer
  • containerId string The containerId of the GTM container you want to interact with

get

Gets the current value of the specified dataLayer variable

Parameters

Returns Promise Promise that resolves to the current value of the variable

getContainerIDs

Returns all active container IDs for the page

Returns array An array of strings containing all container IDs

getDataModel

Returns the the full data model, i. e. the current names and values of all variables in dataLayer

Parameters

  • containerId (optional, default this.containerId)
  • The string GTM Container ID to fetch the data model from. Defaults to the containerId defined on the instance

Returns Promise A Promise that resolves to the data model of dataLayer as an object

getEvents

Returns all dataLayer events matching the given event name

Parameters

Returns array An array of event objects

getLatestEvent

Returns the most recent event matching the specified event name from dataLayer. Simply returns the most recent event if no eventName is specified

Parameters

  • eventName string The event name to match

Returns Promise A Promise that resolves to the latest da event

getLatestMessage

Returns the most recent message from dataLayer

Returns Promise A Promise that resolves to the latest dataLayer message

history

Retrieves all messages that are present in dataLayer

Returns Promise A Promise that resolves to the full dataLayer array

push

Pushes a message (which can be an event) to the dataLayer

Parameters

  • message object The message to push

waitForEvent

Waits for the specified dataLayer event

Parameters

Returns promise A promise that resolves as soon as the event happens