Add Google Analytics to all HTML files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# From: dotenx.com | |
# description: | |
# Add Google Analytics to all HTML files in a directory. Google Analytics code should be in a file called google-analytics in the same directory as this script. | |
# usage: | |
# ./add-gtag.sh directory | |
# Tested on Mac-zsh | |
directory="$1" | |
if [ -d "$directory" ]; then | |
for file in "$directory"/*.html; do | |
if [[ -f "$file" ]]; then | |
sed -i.bak '/<head>/r google-analytics' $file | |
fi | |
done | |
else | |
echo "Directory not found." | |
fi | |
rm $directory/*.bak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment