<p>You should just be able to put it in a text field and then output it in an <a href="http://buildwithcraft.com/docs/templating/includejs" rel="nofollow"><code>includeJs</code></a> statement. So, add a new global set (called 'googleAnalytics' or whatever); create a text field (called 'text' or whatever); and add the new field to your global set field layout.</p>

<p>In your template you should be able to access it by the globalSet handle.</p>

<pre><code>{% includeJs googleAnalytics.text %}
</code></pre>

<p>Not tested, but I don't see any reason it shouldn't work. If the <a href="http://buildwithcraft.com/docs/templating/includejs" rel="nofollow"><code>includeJs</code></a> statement doesn't like that for some reason you can try the following instead.</p>

<pre><code>{% set GACode %}
    {{ googleAnalytics.text }}
{% endset %}
{% includeJs GACode %}
</code></pre>

CC BY-SA 3.0
2018-01-06T17:09:46.253Z
I tried this. What should be the correct field type for the text? I tried both Plain text and Rich Text. Both don't seem to work.
Anya Dit
CC BY-SA 3.0
2018-01-08T20:13:14.880Z
I would suggest plaintext. You may also need to use `raw` filter, so that it is not HTML encoded (i.e. `{{ googleAnalytics.text|raw }}`)
Douglas McDonald
CC BY-SA 3.0
2015-02-19T00:55:25.097Z
2015-02-19T15:48:38.543Z
2015-02-19T15:48:38.543Z
Douglas McDonald
<p>can anyone tell me step by step what to do to put google analytics code into a global field? I have read the earlier answer but i am new to craft and i don't know where to start. </p>

<analytics>
How do i put google analytics code into a Global field?
# How do i put google analytics code into a Global field?

(Asked by: username_0 on 2015-02-18)

can anyone tell me step by step what to do to put google analytics code into a global field? I have read the earlier answer but i am new to craft and i don't know where to start.

**Tags:** analytics


---

## 1 answers

### Answer by username_1 on 2015-02-19. Score: 5

You should just be able to put it in a text field and then output it in an includeJs statement. So, add a new global set (called 'googleAnalytics' or whatever); create a text field (called 'text' or whatever); and add the new field to your global set field layout.
In your template you should be able to access it by the globalSet handle.
{% includeJs googleAnalytics.text %}

Not tested, but I don't see any reason it shouldn't work. If the includeJs statement doesn't like that for some reason you can try the following instead.
{% set GACode %}
    {{ googleAnalytics.text }}
{% endset %}
{% includeJs GACode %}

> **Comments:**
> **username_2**: I tried this. What should be the correct field type for the text? I tried both Plain text and Rich Text. Both don't seem to work.  
> **username_1**: I would suggest plaintext. You may also need to use `raw` filter, so that it is not HTML encoded (i.e. `{{ googleAnalytics.text|raw }}`)  

---

