@croct/plug-google-analytics
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published

Croct
Google Analytics Plugin
A PlugJS plugin for exporting events to Google Analytics.

Version Build Maintainability Coverage

📦 Releases · 🐞 Report Bug · Request Feature

Installation

The recommended way to install this plugin is using NPM. It pairs nicely with module bundlers such as Rollup, Webpack or Browserify and includes Typescript typings.

Run the following command to install the latest version:

npm install @croct/plug-google-analytics

Basic usage

import croct from '@croct/plug';
// Install the plugin
import '@croct/plug-google-analytics';

croct.plug({
    plugins: {
        googleAnalytics: {
            category: 'Croct',
            rateLimit: 1000,
            events: {
                eventOccurred: true,
                testGroupAssigned: false,
            },
            customEvents: {
                customEventName: true,
            },
        },
    }
});

Notice that all Analytics libraries implement a rate-limiting mechanism that ensures you don't send too many hits at once, meaning that some events can be lost. The "rateLimit" option allows you to limit the maximum number of hits in a given interval. For example, passing 500ms causes the function to be called at most one time per 500ms – or two times per second.

Note that although calls are queued for execution but never ignored, events can still be lost if the user leaves the page before all events are sent to Analytics.

Contributing

Contributions to the package are always welcome!

  • Report any bugs or issues on the issue tracker.
  • For major changes, please open an issue first to discuss what you would like to change.
  • Please make sure to update tests as appropriate.

Testing

Before running the test suites, the development dependencies must be installed:

npm install

Then, to run all tests:

npm run test

Run the following command to check the code against the style guide:

npm run lint

Building

Before building the project, the dependencies must be installed:

npm install

Then, to build the CommonJS module:

npm run build

Copyright Notice

This project is released under the MIT License.

Package Sidebar

Install

npm i @croct/plug-google-analytics

Weekly Downloads

0

Version

0.4.1

License

MIT

Unpacked Size

14.6 kB

Total Files

9

Last publish

Collaborators

  • marcospassos
  • fryuni
  • croct-bot