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

@bolt/analytics-autolink

Package Overview
Dependencies
Maintainers
5
Versions
371
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bolt/analytics-autolink

Adds Google Analytics tracking support to the Bolt Design System.

  • 3.0.0
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-71.87%
Maintainers
5
Weekly downloads
 
Created
Source

Helper library to automatically applies GA autolink click tracking query strings to Bolt components that point to external domains.

Install

npm install @bolt/analytics-autolink

Usage

Step 1. Pull in the JS bundle into your local front-end build.

  • Via Bolt's .boltrc.js config:
module.exports = {
  components: {
    global: [
      '@bolt/analytics-autolink',
      //...
    ]
  }
}
  • Or for existing build processes (ex. Webpack), simply import the main JS bundle:
// ex. main.js
import '@bolt/analytics-autolink';
//

For example, a typical GA config might look similar to this:

<head>
  <script src="https://www.google-analytics.com/analytics.js" async></script>

  <script>
    // replace with your own GA tracking #
    const TRACKING_ID = 'UA-123456789-0'; 

    // prep GA data if it doesn't yet exist
    window.ga = window.ga || ((...args) => (ga.q = ga.q || []).push(args));

    ga('create', TRACKING_ID, 'auto', { allowLinker: true });
    ga('send', 'pageview');
    ga('set', 'transport', 'beacon');
    ga('require', 'linker');

    // See Step 3 below on configuring which domains to track
    // window.bolt = window.bolt || {};
    // window.bolt.analytics = window.bolt.analytics || {};
    // window.bolt.analytics.autolink = window.bolt.analytics.autolink || {
    //   domains: ['google.com'] // domains to configure
    // };
    // ga('linker:autoLink', window.bolt.analytics.autolink.domains);
  </script>

Option 1. Via a global Bolt config. For example:

  <script>
    window.bolt = window.bolt || {};
    window.bolt.autolink = {
      domains: ['google.com'], // domains to track
    };

    // make sure GA's linker:autoLink points to the domains configured
    ga('linker:autoLink', window.bolt.autolink.domains);
  </script>

Option 2. This can also be configured via a Drupal config. For example:

  <script>
    window.drupalSettings = {
      google_analytics: {
        trackCrossDomains: ['pega.com'], // domains to track
      },
    };

    // make sure GA's linker:autoLink points to the domains configured
    ga('linker:autoLink', window.drupalSettings.google_analytics.trackCrossDomains);
  </script>

Keywords

FAQs

Package last updated on 08 Jan 2021

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