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
- Host: GitHub
- URL: https://github.com/nwtgck/google-analytics-injector-npm
- Owner: nwtgck
- License: mit
- Created: 2019-03-03T08:04:21.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2021-07-25T16:45:56.000Z (almost 5 years ago)
- Last Synced: 2025-02-04T01:17:07.990Z (over 1 year ago)
- Topics: google-analytics, injection, injector, insert, javascript, tracking-id, typescript
- Language: TypeScript
- Homepage:
- Size: 402 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# google-analytics-injector
[](https://www.npmjs.com/package/google-analytics-injector) [](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/
```