setup-google-analytics
Skill0 starsChanged 10 months agoMITView on GitHub
Set up Google Analytics 4 for a website using Playwright browser automation. Creates GA4 property, gets measurement ID, and adds tracking code to HTML.
In this repository2 other files it gives its agents.
- batik-checkinSkill
- npm-supply-chain-auditSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 10 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 33
If sign-in page appears, inform user to log in via Playwright browser window
- Distinctive: line 34
Wait for user confirmation before proceeding
- Distinctive: line 64
Check "Understand web and/or app traffic" checkbox (or most relevant option)
- Distinctive: line 78
After stream creation, a dialog shows the Google tag code
- Very specific: line 86
Search for index.html in project: Glob("/index.html")
- Distinctive: line 87
Read the HTML file
- Very specific: line 88
Add GA4 tracking code immediately after <head> tag:
- Distinctive: line 105
If the website has JavaScript files with button click handlers:
- Very specific: line 107
Search for existing analytics placeholders: Grep("analytics", path=".")
- Distinctive: line 108
Add gtag event calls for important actions:
- Distinctive: line 123
Property limit reached: Check account limits, may need different account
- Very specific: line 129
Always use browser_snapshot before interacting to see current state
- Distinctive: line 130
Use element refs from snapshot (like "e123", "f10e5") for accurate targeting
- Distinctive: line 133
Wait for page transitions if needed
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Google Analytics 4 Setup
Automate GA4 setup for any website via Playwright browser automation.
Prerequisites
- Playwright MCP server must be running
- Google account with Analytics access (user must be logged in via Playwright browser)
- Website codebase accessible for adding tracking code
Required Information
Collect from user if not provided:
- Website URL (e.g., example.com) - use $ARGUMENTS if provided
- Property Name (defaults to domain name)
- Industry Category (Computers & Electronics, Business, etc.)
- Business Size (Small/Medium/Large/Very Large)
Setup Workflow
Step 1: Check Login Status
- Navigate to
https://analytics.google.com - Take snapshot to verify login
- If sign-in page appears, inform user to log in via Playwright browser window
- Wait for user confirmation before proceeding
Step 2: Navigate to Admin
- Once logged in, click "Admin" in left sidebar
- Take snapshot to confirm Admin page loaded
Step 3: Create New Property
- Click "Create" button in Admin
- Select "Property" from dropdown menu
- Take snapshot to see property creation form
Step 4: Property Details
- Enter property name in "Property name" textbox
- Select timezone if needed (defaults to US/Los Angeles)
- Select currency if needed (defaults to USD)
- Click "Next" button
Step 5: Business Details
- Click industry category dropdown
- Select appropriate category (e.g., "Computers & Electronics")
- Select business size radio button (typically "Small - 1 to 10 employees")
- Click "Next" button
Step 6: Business Objectives
- Take snapshot to see objectives
- Check "Understand web and/or app traffic" checkbox (or most relevant option)
- Click "Create a property" button
Step 7: Set Up Web Data Stream
- On "Data collection" page, click "Web" platform button
- Dialog opens for web stream setup
- Enter website URL in "Website URL" textbox (without https://)
- Enter stream name in "Stream name" textbox (e.g., "Website Name Website")
- Enhanced measurement is enabled by default (leave on)
- Click "Create & continue" button
Step 8: Get Measurement ID
- After stream creation, a dialog shows the Google tag code
- CRITICAL: Extract the measurement ID (format: G-XXXXXXXXXX)
- The ID appears in the script snippet and in stream details
- Take screenshot for reference
- Close the tag instructions dialog
Step 9: Add Tracking Code to Website
- Search for
index.htmlin project:Glob("**/index.html") - Read the HTML file
- Add GA4 tracking code immediately after
<head>tag:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>Replace G-XXXXXXXXXX with actual measurement ID.
Step 10: Add Event Tracking (Optional)
If the website has JavaScript files with button click handlers:
- Search for existing analytics placeholders:
Grep("analytics", path=".") - Add gtag event calls for important actions:
// Example: Track button clicks
if (typeof gtag !== 'undefined') {
gtag('event', 'button_click', {
'event_category': 'engagement',
'event_label': buttonText
});
}Error Handling
- Not logged in: Inform user to log in via Playwright browser, then resume
- Property limit reached: Check account limits, may need different account
- Element not found: Take snapshot to see current page state and adapt
- Session timeout: Restart from Step 1
Tips for Playwright Navigation
- Always use
browser_snapshotbefore interacting to see current state - Use element refs from snapshot (like "e123", "f10e5") for accurate targeting
- For dropdowns: click to open, then click the option
- For date pickers: select year first, then month, then day
- Wait for page transitions if needed
Output
On successful setup, report:
Google Analytics Setup Complete!
Property: [Property Name]
Measurement ID: G-XXXXXXXXXX
Website: https://[domain]
Stream: [Stream Name]
Tracking code added to: [file path]
Enhanced measurement enabled:
- Page views
- Scrolls
- Outbound clicks
- Site search
- Video engagement
- File downloads
Note: Data collection may take up to 48 hours to start appearing in reports.Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

