Skip to content

david-davidson/linktagger.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 

Repository files navigation

linktagger.py

###Tag all your links at once!

Whether you’re on Linux, Mac, or Windows, this Python script lets you add Google link tagging (GLT) in bulk from the command line.

Just run it from the terminal (1), specify the files you’d like to tag (2), and choose from three optional modes (3): -strip removes preexisting GLT, -backup backs up everything it tags, and -rf tags files not only in the target directory, but in all its subdirectories, too.

Like this:

cygwin screenshot

The cool part is that, even on Windows, linktagger supports Unix-style wildcard expansion and (with -rf) iteration through subdirectories. Want to—for some reason—tag not only all the HTML files on your desktop, but also all the HTML files in its subdirectories?

Windows screenshot

(In Unix terminals, put quotation marks around the target files if you’re tagging wildcards recursively—that way the shell won’t expand the wildcards before the script can.)

cygwin screenshot

After that, linktagger will prompt you for GLT parameters and take it from there!

Mac screenshot

linktagger.py knows:

  • To add GLT before section IDs, not after
  • To fix previously tagged links that put a section ID anywhere but the very end of the URL
  • To introduce GLT with “&”, not “?”, when it follows other link parameters that are already set off by a question mark
  • Not to tag links that are already tagged
  • Not to tag unanchored links, like those to a stylesheet or a typeface provider
  • Not to tag relative links, like <a href="#contact">

That is, it’ll tag, say, this: <a href="http://www.test.com#contact?siteid=a">

Like this: <a href="http://www.test.com?siteid=a&utm_source=var1&utm_medium=var2 &utm_content=var3&utm_campaign=var4#contact">

####Requirements:

  • Python 3+, which you can get here
  • An accurate path to where Python lives on your machine: on *nix, run which python (or, if you’re running multiple versions, which python3), and then update the first line of the script
  • Read/write/execute access to linktagger.py: on *nix, just cd into the script’s directory and run chmod 777 linktagger.py

Happy Google link tagging!

P.S. On Linux? Check out linktagger.py’s younger sibling, linkTagger.sh.

About

Python script that automates Google link tagging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages