# Using Different Site Header HTML for Staging

**URL:** <https://community.hubspot.com/t/using-different-site-header-html-for-staging/32006>\
**Category:** CMS Development\
**Tags:** javascript, html\
**Created:** [February 19, 2021, 2:58am UTC](https://community.hubspot.com/t/using-different-site-header-html-for-staging/32006 "2021-02-19T02:58:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvargas2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jvargas2/32/5125_2.png) [@jvargas2](https://community.hubspot.com/u/jvargas2)\
**Post date:** [February 19, 2021, 2:58am UTC](https://community.hubspot.com/t/using-different-site-header-html-for-staging/32006/1 "2021-02-19T02:58:51Z")

</div>

My client has specifically requested the ability to track the staged pages separately from the production tracking in Google Tag Manager, using separate GTM containers. They do not want to have to change the Google Analytics JavaScript each time.

The ideal solution would be to maintain separate “Site Header HTML” for the staging domain but I am unable to connect the staging domain as a secondary domain. Every time I try, I get the following error: “This domain is already connected as a primary, secondary, redirect, or email sending domain.” However, the domain does not show up as any of those, including when I flip the “Display system domains” switch.

Is there anyway to maintain separate Site Header HTML for a staging domain? Is there another solution? There is no strict requirement for using the page staging functionality. They just need to be able to test new pages without having to manually change the tracking code.

I have around 5 years of coding experience, primarily working with Django web applications and Machine Learning engineering, including any devops needs.

I already searched the forum for a few different sets of keywords and read throught the following pages:

- [Use code snippets with HubSpot content](https://knowledge.hubspot.com/cos-general/how-can-i-add-code-snippets-to-the-head-and-footer-html-of-my-pages)
- [https://knowledge.hubspot.com/cos-general/add-your-google-analytics-code-to-your-hubspot-pages-or-blog?\_ga=2.100588702.1638437897.1554681579-1350116256.1554681579&hubs\_post=blog.hubspot.com/marketing/google-analytics&hubs\_post-cta=HubSpot%20users%20can%20follow%20these%20simple%20instructions%20for%20adding%20GA](https://knowledge.hubspot.com/cos-general/add-your-google-analytics-code-to-your-hubspot-pages-or-blog?_ga=2.100588702.1638437897.1554681579-1350116256.1554681579&hubs_post=blog.hubspot.com/marketing/google-analytics&hubs_post-cta=HubSpot%20users%20can%20follow%20these%20simple%20instructions%20for%20adding%20GA)
- [Google Analytics: what It Costs, When To Use, How to Set Up](https://blog.hubspot.com/marketing/google-analytics)
- [Redesign and relaunch a site with content staging](https://knowledge.hubspot.com/cms-general/redesign-and-relaunch-your-site-with-content-staging)

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [February 19, 2021, 3:37pm UTC](https://community.hubspot.com/t/using-different-site-header-html-for-staging/32006/2 "2021-02-19T15:37:34Z")

</div>

Hey @jvargas2. Instead of adding it in site header HTML or as an integration in settings, you could add it in the head code of your templates with an if statement to load different GTM snippets based on domain. You’d have to do the same for the second, smaller GTM snippet too.

```lia-code-sample
<meta charset="utf-8">
<title>{{ content.html_title }}</title>
<meta name="description" content="{{ page_meta.meta_description }}">
<meta name="theme-color" content="#CCD5DD">
<link rel="stylesheet" href="{{ get_public_template_url('[link to css]') }}">
{{ favicon_link }}
{{ standard_header_includes }}
{% if request.domain == 'www.example.com' %}
 // GTM snippet for production
{% elif request.domain == 'www-example-com.sandbox.hs-sites.com'%} // whatever your staging domain is
 // GTM snippet for staging
[% endif %}

```

Alternatively, could you/they not simply set up different views in GA for production and staging? Might be easier, more scalable/manageable, and more useful in the long run (e.g. ability to preview and test GTM changes on staging site that will affect live site).

---

<div class="post-metadata">

**Author:** ![jvargas2](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jvargas2/32/5125_2.png) [@jvargas2](https://community.hubspot.com/u/jvargas2)\
**Post date:** [March 30, 2021, 1:33pm UTC](https://community.hubspot.com/t/using-different-site-header-html-for-staging/32006/3 "2021-03-30T13:33:40Z")

</div>

For anyone else reading this, there was a typo in the snippet and you may not need the www depending on your domain. My final version looked like this:

```lia-code-sample
{% if request.domain == 'example.com' %}
 <!-- GTM snippet for production -->
{% elif request.domain == 'example-com.sandbox.hs-sites.com' %}
 <!-- GTM snippet for staging -->
{% endif %}

```
