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

@d-cat/tag-template-datalayer-starter

v1.4.0

Published

Tag Template build for @d-cat/tag-manager to create a base datalayer setup.

Downloads

20

Readme

Getting started with @d-cat/tag-template-datalayer-starter

codecov

@d-cat/tag-template-datalayer-starter is a tag template that initializes DDM's dataLayer. The Tag Template is designed to use with @d-cat/tag-manager.

Install

npm i @d-cat/tag-template-datalayer-starter

Usage

This template returns a DataLayerStarter that out-of-the-box initializes the dataLayer, for @d-cat/digital-data-manager. Depending on your needs you can enhance the dataLayer with modules.

import DataLayerStarter from '@d-cat/tag-template-datalayer-starter';

const component = new DataLayerStarter({
  event: 'pageview',
  page: window._ddi.page,
  user: window._ddi.user,
  session: window._ddi.session,
});

// default usage
component.render();

Parameters

| Parameters | Type | Desc | | ---------- | :--------------------: | --------------------------------------------------------------------------- | | props | IDataLayerStarterProps | Object that should container a page, user, session, and event prop. |

require(plugin: keyof typeof models.Plugins): void

The require method let you enable modules to enrich the dataLayer. The following modules are available:

  • contextHubZiggo: enables enhancing the dataLayer with contextHub.available.
  • devices: default enabled. enables returning device info.
  • ip2isp: returns an object with ISP data based on the users IP.
  • imadb: returns user data based on an userid, either: sso, pwc or zcid.
  • pageviewCounter: default enabled, counts the amount of pageviews.
  • sessionCounter: default enabled, counts the amount of sessions.
  • qvisits: default enabled. Enables qvisits.

Example

import DataLayer, { Plugins } from '@d-cat/tag-template-datalayer-starter';

const app = new DataLayer();

app.require(Plugins.imadb); // enabled imadb
app.require(Plugins.ip2isp); // enables ip2isp
app.require(Plugins.qvisits); // enables qvisits

app.render(); // executes tag with all modules enabled

userReady(props?: IDataLayerStartProps): Promise<void>

The userReady method stores the user object in DDM's state tree, and it emits a _dd.user.ready.initial event to DDM's event emitter. This object is persisted for the duration of 1 year. You can inherit this behavior.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

class MyClass extends DataLayer {
  constructor(...args: any[]) {
    super(...args);
  }

  public async userReady(...args: any[]): Promise<void> {
    super.userReady(...args);

    // your logic
  }
}

const myAsyncMethod = async () => {
  const myComponent = new MyClass();

  return await myComponent.userReady();
};

sessionReady(props?: IDataLayerStartProps): Promise<void>

The sessionReady method stores the session object in DDM's state tree, and it emits a _dd.session.ready event to DDM's event emitter. This object is persisted for the duration of 30 minutes. You can inherit this behavior.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

class MyClass extends DataLayer {
  constructor(...args: any[]) {
    super(...args);
  }

  public async sessionReady(...args: any[]): Promise<void> {
    super.sessionReady(...args);

    // your logic
  }
}

const myAsyncMethod = async () => {
  const myComponent = new MyClass();

  return await myComponent.sessionReady();
};

pageReady(props?: IDataLayerStartProps): Promise<void>

The pageReady method stores the page object in DDM's state tree, and it emits a _dd.page.ready event to DDM's event emitter. This object is NOT persisted. You can inherit this behavior.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

class MyClass extends DataLayer {
  constructor(...args: any[]) {
    super(...args);
  }

  public async pageReady(...args: any[]): Promise<void> {
    super.pageReady(...args);

    // your logic
  }
}

const myAsyncMethod = async () => {
  const myComponent = new MyClass();

  return await myComponent.pageReady();
};

public static getProduct(sku: string|number): Promise<models.IProductSKU<string | number>>

The static getProduct method returns product data based on a sku.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

const myAsyncMethod = async () => {
  return await DataLayer.getProduct(1); // returns data of product 1
};

ddReady(): void

The ddReady method emits a _dd.ready event to DDM's event emitter. This event is widely used as the initializer of the dataLayer.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

class MyClass extends DataLayer {
  constructor(...args: any[]) {
    super(...args);
  }

  public ddReady(...args: any[]): void {
    super.ddReady(...args);

    // your logic
  }
}

const mySyncMethod = () => {
  const myComponent = new MyClass();

  return myComponent.ddReady();
};

render(props?: IDataLayerStartProps)): void

The render method is for convenience. It invokes all other methods in correct order. It's recommended to inherit from other methods instead of render.

import DataLayer from '@d-cat/tag-template-datalayer-starter';

const mySyncMethod = () => {
  const myComponent = new DataLayer();

  return myComponent.render();
};