0.0.8 • Published 4 years ago

@nartc/scully-plugin-google-gtag v0.0.8

Weekly downloads
40
License
MIT
Repository
github
Last release
4 years ago

scully-plugin-google-gtag

This is a postRenderer plugin that will append necessary script tags to initialize gtag.js to the Scully's pre-rendered pages' <head> tag. This plugin is based on Gatsby's official Gtag plugin

Installation

To install this plugin, run:

npm install -D @nartc/scully-plugin-google-gtag

Usage

import { ScullyConfig, setPluginConfig } from '@scullyio/scully';
import {
  getGaPlugin,
  GoogleAnalyticsConfig,
} from '@nartc/scully-plugin-google-gtag';

const GaPlugin = getGaPlugin();
setPluginConfig(GaPlugin, <GoogleAnalyticsConfig>{
  dryRun: true, // set dryRun to true to enable Gtag in develop mode
  trackingIds: ['YOUR_TRACKING_ID'],
});

export const config: ScullyConfig = {
  projectRoot: './src',
  projectName: 'scully-project',
  outDir: './dist/static',
  defaultPostRenderers: [GaPlugin],
  routes: {
    '/blog/:slug': {
      type: RouteTypes.contentFolder,
      slug: {
        folder: './blog',
      },
      postRenderers: [GaPlugin],
    },
  },
};

Configuration

scully-plugin-google-tag exposes GoogleAnalyticsConfig interface to help you providing the configuration for the plugin and for gtag

GoogleAnalyticsConfig
nametyperequireddescription
dryRunboolean-Set this flag to true if you want to test gtag in development environment. Default to false
trackingIdsstring[]yesList of all tracking IDs that you want gtag to track
gtagConfigGoogleAnalyticsGtagConfig-Gtag specific configuration
pluginConfigGoogleAnalyticsPluginConfig-Plugin specific configuration
GoogleAnalyticsGtagConfig
nametyperequireddescription
anonymize_ipboolean-To set anonymize_ip for gtag
optimize_idstring-To set optimize_id for gtag
[key: string]any-Any other configuration parameters that gtag('config') accepts
GoogleAnalyticsPluginConfig
nametyperequireddescription
respectDNTboolean-Respect DO_NOT_TRACK
excludestring[]-List of excluded paths that gtag will ignore

Questions or Issues

Feel free to open an issue

Contribution

Contribution of any kinds is greatly appreciated

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago