May 30, 2023, 1:33 a.m. | mohsen

DEV Community dev.to

If you have many HTML pages in a directory, adding Google Analytics tracking code to all of them can be a bit frustrating.


In this short tutorial, I show you how to do it with a bash script that automatically does the job.


First, copy the code from your Google Analytics console, and paste it to a file named google-analytics.


Then, write the following code to a file, say add-gtag.sh and give it the execution permission:



chmod u+x ./add-gtag.sh …

analytics bash code google html job seo show tracking tutorial webdev

Founding AI Engineer, Agents

@ Occam AI | New York

AI Engineer Intern, Agents

@ Occam AI | US

AI Research Scientist

@ Vara | Berlin, Germany and Remote

Data Architect

@ University of Texas at Austin | Austin, TX

Data ETL Engineer

@ University of Texas at Austin | Austin, TX

Lead GNSS Data Scientist

@ Lurra Systems | Melbourne