![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A tiny (455B) client-side module for tracking with Google Analytics
This module exposes three module definitions:
dist/ganalytics.es.js
dist/ganalytics.js
dist/ganalytics.min.js
$ npm install --save ganalytics
const GAnalytics = require('ganalytics');
const ga = new GAnalytics('UA-XXXXXXXX-X', { aid:1 });
ga.send('pageview');
ga.send('pageview', { dt:'Foobar', dp:'/foo' });
ga.send('event', { ec:'Video', ea:'Play', el:'Home Hero' });
Type: String
Your Google Analytics tracker ID; eg UA-XXXXXXXX-X
Type: Integer
Default: 0
Anonymize the sender's IP address. See Anonymize IP.
Type: String
Specifies the application's name. See Application Name.
Type: String
Specifies the application identifier. See Application ID.
Type: String
Specifies the application installer identifier. See Application Installer ID.
Type: String
Specifies the application verison. See Application Version.
Type: String
Indicates the data source type of the hit; eg web
or app
. See Data Source.
Type: Function
Default: window.fetch
Provide a custom GET
requestor. It needs to accept a URL as its first and only parameter.
Note: By default, we use
window.fetch
which has somewhat limited browser support.
You may want to checkout unfetch
or provide your current AJAX/XHR library of choice, like axios
.
import fetch from 'unfetch';
import GAnalytics from 'ganalytics';
const ga = new GAnalytics('UA-XXXXXXXX-X', { get:fetch });
const axios = require('axios');
const GAnalytics = require('ganalytics');
const ga = new GAnalytics('UA-XXXXXXXX-X', { get:axios });
// or
const ga = new GAnalytics('UA-XXXXXXXX-X', { get:axios.get });
Type: String
The type of hit to send. Must be one of these: pageview
, screenview
, event
, transaction
, item
, social
, exception
, or timing
.
Type: Object
The parameters to send based on the type
of hit.
Please follow the links for each available parameter set:
For pageview
hits only, if no params
are provided, then the document.title
and location.href
values will be auto-filled. This allows you to send valid requests by writing:
ga.send('pageview');
// is the same as:
//=> ga.send('pageview', { dt:document.title, dl:location.href })
MIT © Luke Edwards
FAQs
A tiny (312B) client-side module for tracking with Google Analytics
The npm package ganalytics receives a total of 276 weekly downloads. As such, ganalytics popularity was classified as not popular.
We found that ganalytics demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.