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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ohto/nuxt-gtag-ecommerce

v0.10.0

Published

A Nuxt 3 module that extends [`nuxt-gtag`](https://nuxt.com/modules/gtag) with a typed API for Google Analytics 4 (GA4) ecommerce events.

Readme

@ohto/nuxt-gtag-ecommerce

A Nuxt 3 module that extends nuxt-gtag with a typed API for Google Analytics 4 (GA4) ecommerce events.

  • Typed helpers for all GA4 ecommerce events
  • Powered by useTrackEvent from nuxt-gtag
  • TypeScript-first (works great with JavaScript too)

Client-only plugin: events are sent from the browser.


Installation

Use your preferred package manager:

npm install nuxt-gtag @ohto/nuxt-gtag-ecommerce
# or
pnpm add nuxt-gtag @ohto/nuxt-gtag-ecommerce
# or
yarn add nuxt-gtag @ohto/nuxt-gtag-ecommerce

Peer requirements:

  • nuxt >= 3
  • nuxt-gtag >= 4

Setup

Add both modules to nuxt.config.ts in this order (gtag first):

export default defineNuxtConfig({
  modules: [
    "nuxt-gtag", // must be before the ecommerce module
    "@ohto/nuxt-gtag-ecommerce",
  ],
  gtag: {
    id: "G-XXXXXXXXXX",
  },
});

$trackCommerce is injected into the app context and component instance:

  • Composition API: const { $trackCommerce } = useNuxtApp()
  • Options API: this.$trackCommerce

Types

All payloads are typed. You can import the types if you want explicit annotations:

import type {
  IGA4Item,
  IViewItemParams,
  IViewItemListParams,
  ISelectItemParams,
  IAddToCartParams,
  IRemoveFromCartParams,
  IViewCartParams,
  IBeginCheckoutParams,
  IAddPaymentInfoParams,
  IAddShippingInfoParams,
  IPurchaseParams,
  IRefundParams,
} from "@ohto/nuxt-gtag-ecommerce";

Notes:

  • GA4 expects items arrays. For single-item events like viewItem and selectItem, pass a single-element array.
  • Provide currency and value at the event level where required by GA4.

API Reference and Examples

Each method calls the matching GA4 ecommerce event under the hood.

viewItem — view_item

<script setup lang="ts">
import type { IGA4Item, IViewItemParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const item: IGA4Item = {
  item_id: "SKU123",
  item_name: "Hat",
  price: 25,
  quantity: 1,
};
const payload: IViewItemParams = { currency: "USD", value: 25, items: [item] };

$trackCommerce.viewItem(payload);
</script>

viewItemList — view_item_list

<script setup lang="ts">
import type { IGA4Item, IViewItemListParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const items: IGA4Item[] = [
  { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 1 },
  { item_id: "SKU456", item_name: "Scarf", price: 15, quantity: 1 },
];
const payload: IViewItemListParams = {
  items,
  item_list_id: "home_rec_1",
  item_list_name: "Recommended",
};

$trackCommerce.viewItemList(payload);
</script>

selectItem — select_item

<script setup lang="ts">
import type { IGA4Item, ISelectItemParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const selected: IGA4Item = {
  item_id: "SKU456",
  item_name: "Scarf",
  price: 15,
  quantity: 1,
};
const payload: ISelectItemParams = {
  items: [selected],
  item_list_id: "home_rec_1",
  item_list_name: "Recommended",
};

$trackCommerce.selectItem(payload);
</script>

addToCart — add_to_cart

<script setup lang="ts">
import type { IGA4Item, IAddToCartParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const item: IGA4Item = {
  item_id: "SKU123",
  item_name: "Hat",
  price: 25,
  quantity: 1,
};
const payload: IAddToCartParams = { currency: "USD", value: 25, items: [item] };

$trackCommerce.addToCart(payload);
</script>

removeFromCart — remove_from_cart

<script setup lang="ts">
import type {
  IGA4Item,
  IRemoveFromCartParams,
} from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const item: IGA4Item = {
  item_id: "SKU123",
  item_name: "Hat",
  price: 25,
  quantity: 1,
};
const payload: IRemoveFromCartParams = {
  currency: "USD",
  value: 25,
  items: [item],
};

$trackCommerce.removeFromCart(payload);
</script>

viewCart — view_cart

<script setup lang="ts">
import type { IGA4Item, IViewCartParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const items: IGA4Item[] = [
  { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 1 },
  { item_id: "SKU456", item_name: "Scarf", price: 15, quantity: 2 },
];
const payload: IViewCartParams = { currency: "USD", value: 55, items };

$trackCommerce.viewCart(payload);
</script>

beginCheckout — begin_checkout

<script setup lang="ts">
import type { IGA4Item, IBeginCheckoutParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const items: IGA4Item[] = [
  { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 1 },
];
const payload: IBeginCheckoutParams = {
  currency: "USD",
  value: 25,
  items,
  coupon: "WELCOME10",
};

$trackCommerce.beginCheckout(payload);
</script>

addPaymentInfo — add_payment_info

<script setup lang="ts">
import type {
  IGA4Item,
  IAddPaymentInfoParams,
} from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const items: IGA4Item[] = [
  { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 1 },
];
const payload: IAddPaymentInfoParams = {
  currency: "USD",
  value: 25,
  items,
  payment_type: "card",
};

$trackCommerce.addPaymentInfo(payload);
</script>

addShippingInfo — add_shipping_info

<script setup lang="ts">
import type {
  IGA4Item,
  IAddShippingInfoParams,
} from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const items: IGA4Item[] = [
  { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 1 },
];
const payload: IAddShippingInfoParams = {
  currency: "USD",
  value: 30,
  items,
  shipping_tier: "express",
};

$trackCommerce.addShippingInfo(payload);
</script>

purchase — purchase

<script setup lang="ts">
import type { IPurchaseParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const payload: IPurchaseParams = {
  transaction_id: "T12345",
  value: 100,
  currency: "USD",
  tax: 8,
  shipping: 5,
  items: [
    { item_id: "SKU123", item_name: "Hat", price: 25, quantity: 2 },
    { item_id: "SKU456", item_name: "Scarf", price: 15, quantity: 2 },
  ],
};

$trackCommerce.purchase(payload);
</script>

refund — refund

<script setup lang="ts">
import type { IRefundParams } from "@ohto/nuxt-gtag-ecommerce";
const { $trackCommerce } = useNuxtApp();

const payload: IRefundParams = {
  transaction_id: "T12345",
  // optional: value, currency, items
};

$trackCommerce.refund(payload);
</script>

Notes

  • The module logs a console warning if nuxt-gtag isn’t found in your modules list, but still registers client helpers in case gtag is available via another path.
  • Events are only sent client-side (plugin is mode: 'client').

License

MIT