Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-analytics-protocol

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-analytics-protocol

A tiny library that reimplements Google Analytics calls using the [Google Analytics Measurement Protocol](https://developers.google.com/analytics/devguides/collection/protocol/v1/).

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

google-analytics-protocol.js

A tiny library that reimplements Google Analytics calls using the Google Analytics Measurement Protocol.

Why?

Google's own analytics JS file requires a number of browser features, like cookies and XHR. Service Workers do not have access to cookies, localStorage and the like, and we also want to be more deliberate about versioning and caching when it comes to Service Workers. So this is a "fresh" rewrite, using fetch and IndexedDB.

Requirements

Since this is designed for use inside Service Workers I haven't added any shims for older browsers. So it requires IndexedDB, fetch and Promise support.

Additional features

Again, given the Service Worker nature of what we're doing, it caches analytics calls inside the IndexedDB, so if it cannot connect to the GA server it'll store requests offline and try the next time an analytics call is made.

How do I use it?

The actual call itself is very basic and uses the attributes specified in the protocol reference.

Use setAnalyticsID() to specify your ID before trying to send any calls.

import Analytics from 'google-analytics-protocol';

Analytics.setAnalyticsID(GA_ID);

Analytics({
    t: 'pageview',
    dh: 'localhost.com',
    dp: '/index.html'
})

FAQs

Package last updated on 01 Jun 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc