Node.js CLI to insert Google Tag Manager and Google Analytics code into your HTML files.
npm install -g @tuckn/insert-gtag
or download a released binary file.
on CLI
$ insert-gtag analytics --help
Usage: insert-gtag analytics [options] <dirPath> <trackingId>
Insert Google Analytics code (gtag.js) in html files
Options:
-V, --version output the version number
-M, --matched-reg-exp <exp> RegExp pattern of extensions of file to be inserted. Default.
"\.html?$"
-I, --ignored-reg-exp <exp> RegExp pattern of file to be exclude. Ex. "[_\-.]cache\d+"
-N, --indents <number> Number of indenting white spaces. Default: 4
-h, --help display help for command
The below is example.
$ insert-gtag analytics "D:\HtmlDir1" "UA-XXXXXX-Y"
done
$ insert-gtag analytics "D:\HtmlDir2" --indents 2 "UA-XXXXXX-Y" "AW-XXXXXXXXXX"
done
on Node.js
const { insertGtagCode } = require('@tuckn/insert-gtag');
await insertGtagCode('D:\\HtmlDir', 'UA-9999-9', {
ignoredRegExp: 'Excluding Name',
});
on CLI
$ insert-gtag tag-manager --help
Usage: insert-gtag tag-manager [options] <dirPath> <gtmId>
Insert Google Tag Manager code in html files
Options:
-V, --version output the version number
-M, --matched-reg-exp <exp> RegExp pattern of extensions of file to be inserted. Default.
"\.html?$"
-I, --ignored-reg-exp <exp> RegExp pattern of file to be exclude. Ex. "[_\-.]cache\d+"
-N, --indents <number> Number of indenting white spaces. Default: 4
-h, --help display help for command
The below is example.
$ insert-gtag tag-manager "D:\HtmlDir" "GTM-XXXXXXX"
on Node.js
const { insertGTagManagerCode } = require('@tuckn/insert-gtag');
await insertGTagManagerCode('D:\\HtmlDir', 'GTM-XXXXXXX', {
ignoredRegExp: 'Excluding Name',
});
See all specifications here.
MIT
Copyright (c) 2020 Tuckn