An open API service indexing awesome lists of open source software.

https://github.com/nwtgck/google-analytics-injector-npm

CLI for injecting Google Analytics Tracking Snippet to HTML files
https://github.com/nwtgck/google-analytics-injector-npm

google-analytics injection injector insert javascript tracking-id typescript

Last synced: over 1 year ago
JSON representation

CLI for injecting Google Analytics Tracking Snippet to HTML files

Awesome Lists containing this project

README

          

# google-analytics-injector
[![npm](https://img.shields.io/npm/v/google-analytics-injector.svg)](https://www.npmjs.com/package/google-analytics-injector) [![CircleCI](https://circleci.com/gh/nwtgck/google-analytics-injector-npm.svg?style=shield)](https://circleci.com/gh/nwtgck/google-analytics-injector-npm)

Inject Google Analytics Tracking Snippet

## Installation

Install `google-analytics-injector` command as follows.

```bash
npm i -g google-analytics-injector
```

## Usage

Suppose your have `myfile.html` as follows.

```html

My File

```

Type the following command to inject tracking ID, `"UA-XXXXX-Y"` to `myfile.html`.

```bash
google-analytics-injector -t UA-XXXXX-Y myfile.html
```

Then, you have injected `myfile.html` as follows.

```html

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');

My File

```

### Inject recursively

Suupose `mydist` is a directory which contains .html files. The files injected recursively.

```bash
google-analytics-injector -t UA-XXXXX-Y ./mydist/
```