Analytics Architecture on Google Sites
Google Sites is a highly restricted website builder with no access to page templates, source code, <head> tags, or server configuration. There is no theme editing, no plugin system, and no JavaScript execution in the standard page rendering context.
The only injection point for custom code is the Embed HTML widget, which renders content inside a sandboxed <iframe>. This sandbox severely limits what analytics implementations can achieve.
What Google Sites provides:
- Built-in Google Analytics integration (measurement ID only, no custom configuration)
- Embed HTML widget (sandboxed iframe, limited script execution)
- No access to
<head>,<body>, or any template markup - No custom CSS injection outside of the embed widget
- No server-side processing
What Google Sites does not allow:
- Direct GTM container installation
- Data layer construction on the parent page
- Cross-domain tracking configuration
- Custom JavaScript on the main page DOM
- Cookie manipulation on the parent domain
- Modification of HTTP headers or response behavior
Installing Tracking Scripts
Method 1: Built-In Google Analytics (Recommended)
The only officially supported analytics method. Configure it in Google Sites settings:
- Open the site in the Google Sites editor
- Click the gear icon (Settings)
- Select "Analytics"
- Enter your Google Analytics Measurement ID (format:
G-XXXXXXXXXX) - Publish the site
This injects the GA4 gtag.js snippet into the page <head> automatically. You cannot customize the gtag configuration, add custom parameters, or modify the default event behavior through this method.
The built-in integration sends:
page_viewevents with standard parameters- Basic user properties (language, screen resolution)
- Default enhanced measurement events (scroll, outbound clicks, site search, file downloads)
You cannot configure:
- Custom events or parameters
- Custom dimensions or metrics
- Cross-domain tracking
- Content grouping
- User ID tracking
- Consent mode settings
Method 2: Embed HTML Widget (Limited)
Insert an Embed HTML block on each page:
- In the editor, click Insert > Embed > Embed code
- Paste an HTML/JavaScript snippet
- The code renders inside a sandboxed iframe
<!-- This runs inside a sandboxed iframe, NOT on the parent page -->
<script>
// This script can only access the iframe's DOM, not the parent page
// It cannot read the parent URL, set cookies on the parent domain,
// or interact with the parent page's dataLayer
// You can send a Measurement Protocol hit directly
const measurementId = 'G-XXXXXXXXXX';
const apiSecret = 'YOUR_API_SECRET';
fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`, {
method: 'POST',
body: JSON.stringify({
client_id: crypto.randomUUID(),
events: [{
name: 'widget_view',
params: {
widget_name: 'embedded_content',
}
}]
})
});
</script>
Limitations of the embed approach:
- The iframe is sandboxed; scripts cannot access
window.parent - Each embed widget is an isolated context with no shared state
- The embed does not persist across page navigations
- You must add the embed to every page individually
- The iframe dimensions are fixed and may affect layout
Data Layer Implementation
A true data layer (window.dataLayer) is not possible on Google Sites because:
- You cannot inject JavaScript into the parent page's DOM
- The built-in GA integration does not expose a configurable data layer
- Embed widgets run in sandboxed iframes that cannot write to the parent window
Workaround: Measurement Protocol Direct Hits
For specific tracking needs beyond the built-in GA4 integration, use the GA4 Measurement Protocol from embed widgets:
<script>
(async function() {
const measurementId = 'G-XXXXXXXXXX';
const apiSecret = 'YOUR_API_SECRET';
// Generate or retrieve a client ID
let clientId = localStorage.getItem('_ga_cid');
if (!clientId) {
clientId = crypto.randomUUID();
localStorage.setItem('_ga_cid', clientId);
}
await fetch(
`https://www.google-analytics.com/mp/collect?measurement_id=${measurementId}&api_secret=${apiSecret}`,
{
method: 'POST',
body: JSON.stringify({
client_id: clientId,
events: [{
name: 'custom_interaction',
params: {
interaction_type: 'form_submit',
page_location: document.referrer || 'unknown'
}
}]
})
}
);
})();
</script>
Note: localStorage in the iframe is scoped to the embed origin, not the Google Sites domain. The client ID will not match the one set by the built-in GA4 integration.
Common Issues
GTM container cannot be installed. Google Sites does not allow script injection into the page <head> or <body>. The built-in GA integration is the only method that has access to the actual page DOM. GTM requires direct <head> access, which is not available.
Embed widget scripts run in a sandbox. All code in Embed HTML widgets is rendered inside an iframe with restricted permissions. Scripts cannot access window.parent, set cookies on the parent domain, or interact with the built-in GA tracking instance.
No cross-page state persistence. Each page load on Google Sites creates a fresh context. The embed widget iframe is destroyed and recreated on navigation. There is no mechanism for passing data between pages outside of what the built-in GA4 integration handles automatically.
Built-in GA shows limited data. The built-in integration only sends default GA4 events. There is no way to add custom parameters, modify the gtag configuration, or implement consent mode through the Google Sites interface.
Enhanced measurement may not capture all interactions. Enhanced measurement in GA4 relies on specific DOM patterns for features like outbound click tracking and file download tracking. Google Sites' generated HTML may not match these patterns consistently.
Platform-Specific Considerations
Google Sites is not designed for analytics-intensive implementations. If your requirements include custom event tracking, data layer construction, GTM container deployment, consent management, or cross-domain tracking, Google Sites is not the appropriate platform.
For organizations locked into Google Sites (often due to Google Workspace policies), the realistic analytics stack is:
- Built-in GA4 integration for pageview and basic engagement data
- GA4 enhanced measurement for automated interaction tracking
- Measurement Protocol from embed widgets for specific custom events (with the understanding that these events will not share a session with the built-in tracking)
Google Sites pages are served from sites.google.com (or a custom domain via CNAME). The built-in GA4 integration handles the domain correctly, but any Measurement Protocol hits from embed widgets will show a different origin.
Server-side analytics (log analysis, server timing) are not available. Google Sites is a fully managed platform with no access to server logs, HTTP headers, or response configuration.