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.
1 Answer
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 %}
-
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 DitJan 6, 2018 at 17:09
-
I would suggest plaintext. You may also need to use
raw
filter, so that it is not HTML encoded (i.e.{{ googleAnalytics.text|raw }}
) Jan 8, 2018 at 20:13