# Google Analytics in Perspective

**URL:** <https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 18, 2019, 1:47pm UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195 "2019-10-18T13:47:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janne](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Janne](https://forum.inductiveautomation.com/u/Janne)\
**Post date:** [October 18, 2019, 1:47pm UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/1 "2019-10-18T13:47:13Z")

</div>

We would like to embed Google Analytics code to Perspective web pages in order to see what pages our customers are using. Any guidelines where to put it?

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [October 18, 2019, 6:58pm UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/2 "2019-10-18T18:58:45Z")

</div>

I spoke to @Carl.Gould at ICC and he told me this is possible, hopefully he can pitch in here and advise!

---

<div class="post-metadata">

**Author:** ![Janne](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@Janne](https://forum.inductiveautomation.com/u/Janne)\
**Post date:** [October 29, 2019, 5:31am UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/3 "2019-10-29T05:31:06Z")

</div>

@Carl.Gould Could you comment this?

---

<div class="post-metadata">

**Author:** ![PavanYarlagadda](https://avatars.discourse-cdn.com/v4/letter/p/8baadc/32.png) [@PavanYarlagadda](https://forum.inductiveautomation.com/u/PavanYarlagadda)\
**Post date:** [November 1, 2022, 2:58am UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/4 "2022-11-01T02:58:56Z")

</div>

Are you able to figure out a way to add google analytics to your app?

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [November 2, 2022, 9:41am UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/5 "2022-11-02T09:41:21Z")

</div>

Might be able to inject the google javascript with the markdown component.

> [@Javascript inject in Perspective... have fun](https://forum.inductiveautomation.com/t/javascript-inject-in-perspective-have-fun/65805):
>
> Soo i'll just link this here... You can do whatever with it, but its not really gonna be clean or easy xD Have fun man_mage WARNING Dont let userinput enter in here

---

<div class="post-metadata">

**Author:** ![simeonw](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@simeonw](https://forum.inductiveautomation.com/u/simeonw)\
**Post date:** [July 19, 2024, 3:15am UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/6 "2024-07-19T03:15:51Z")

</div>

Using the markdown component:

```python
	code = """<img style='display:none' 
         src='/favicon.ico' 
         onload="
            const scriptElement = document.querySelector('script#ga4tag');
            if (!scriptElement) {
                const script = document.createElement('script');
                script.async = true;
                script.id = 'ga4tag';
                script.src = 'https://www.googletagmanager.com/gtag/js?id=<your-ga-tag>';

                const configScript = document.createElement('script');
                configScript.innerHTML = \`
                    window.dataLayer = window.dataLayer || [];
                    function gtag(){dataLayer.push(arguments);}
                    gtag('js', new Date());
                    gtag('config', '<your-ga-tag>');
                \`;

                document.body.appendChild(script);
                document.body.appendChild(configScript);
            }
       ">
	</img>""".replace("\n", "").replace("\t", "").replace("<your-ga-tag>",value)

	return code
	

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/8/a815da5046d9696d336d6f25a2f8a372adf50b34.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 19, 2024, 6:55am UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/7 "2024-07-19T06:55:38Z")

</div>

For something static like this that should work on every view, you could also use something like this to inject the script directly on the page without markdown

> [@\[feature-748\]Perspective Favicon](https://forum.inductiveautomation.com/t/feature-748-perspective-favicon/24642/29):
>
> Soo i got something for you mage Create these files (and injectables folder) (depending on install folder ofc) "C:\Program Files\Inductive Automation\Ignition\data\modules\com.inductiveautomation.perspective\injectables\head\_bottom.txt" "C:\Program Files\Inductive Automation\Ignition\webserver\webapps\main\newFavicon.ico" In the head\_bottom.txt put this: \<script\> const oldLinks = document.querySelectorAll('link[rel\*="icon"]'); oldLinks.forEach(e =\> {e.href = '/newFavicon.ico';}); \</script\>…

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 19, 2024, 2:39pm UTC](https://forum.inductiveautomation.com/t/google-analytics-in-perspective/29195/8 "2024-07-19T14:39:13Z")

</div>

Spoilers: Analytics on the public demo project is exactly what we created the "injectables" stuff for.
