Socket
Socket
Sign inDemoInstall

ga4-mp

Package Overview
Dependencies
4
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ga4-mp

Send data to Google Analytics 4 using Measurement Protocol


Version published
Weekly downloads
139
decreased by-22.35%
Maintainers
1
Install size
1.94 MB
Created
Weekly downloads
 

Readme

Source

Google Analytics GA4 Measurement Protocol Library

This library provides an interface for sending data to Google Analytics 4 properties using Measurement Protocol.

NOTE Google Analytics 4 is in Alpha as of the latest update

Use

BSD 3-Clause license can be found in ./LICENSE

Contact

analytics-help@adswerve.com

Compatible with

  • Node.js version 8+
  • es2015

Installation

npm install -s ga4-mp

Setup

ga4mp = require('ga4-mp');
let ga4 = ga4mp.createClient(apiSecret, measurementId, clientId);

Send Hits to GA4 Account

You can send events to GA4 as they happen or batch them to be sent at another time of your choosing.

Send immediately

ga4.send(<events>);

Send later

ga4.send(<events>, true); // Set postpone flag
ga4.flushBuffer();  // Send all postponed events

Events passed to send()

var events = [
  {
    name : 'add_to_cart',
    params : {
      currency : 'USD',
       items : ['Pokémon cards'],
       value : "4.99"
    }
  },
  {
    name : 'app_update',
    params : {
      previous_app_version : '4.6'
    }
  }
]

Events are expected to be passed to the send() function within an array and matching the object schema found in the Google Analytics 4 documentation.

Additional Features

Set and unset a constant parameter

ga4.setConstantParam(key, value);  // Set a constant
ga4.unsetConstantParam(key); // Remove a constant

Set custom dimensions/metrics, country codes, etc. for all outgoing events. You can unset them too.

Output connection details

ga4.readClientInfo();

Keywords

FAQs

Last updated on 06 Nov 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc