Skip to content

Instantly share code, notes, and snippets.

@mkamrani
Created May 30, 2023 01:12
Show Gist options
  • Select an option

  • Save mkamrani/a159516f73db0e8adf10e5d88ec2a370 to your computer and use it in GitHub Desktop.

Select an option

Save mkamrani/a159516f73db0e8adf10e5d88ec2a370 to your computer and use it in GitHub Desktop.

Revisions

  1. mkamrani created this gist May 30, 2023.
    26 changes: 26 additions & 0 deletions add-gtag.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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