Creating a WordPress.com Plugin for Google Tag Manager (GTM)

I wanted to add GTM to this website. Here are the steps using Claude to create the plugin I needed:

  1. Requested code for the plugin from Claude.
  2. Uploaded code to Github: https://github.com/adman54/simple-google-tag-manager
  3. Installation Instructions
    • Save the file: Copy the code above and save it as simple-google-tag-manager.php
    • Create a plugin folder:
      • Create a folder named simple-google-tag-manager
      • Place the PHP file inside this folder
    • Upload to WordPress:
      • Zip the simple-google-tag-manager folder
      • Go to WordPress Admin → Plugins → Add New → Upload Plugin
      • Upload the zip file and activate
    • Configure:
      • Go to Settings → Google Tag Manager
      • Enter your GTM Container ID (format: GTM-XXXXXXX)
      • Click Save Settings

Features

Simple interface: Clean admin page under Settings menu

Validation: Ensures GTM ID format is correct

Proper placement: Adds code to both and after as Google recommends

Security: Sanitizes and escapes all inputs/outputs

Quick access: Settings link appears directly on the plugins page

Posted in

Leave a Reply

Discover more from Adman Analytics

Subscribe now to keep reading and get access to the full archive.

Continue reading