I'm trying to add additional logic to my site to better track logged in users vs non logged in user activity. If you set a gtag with the user_id name, it will tie that session to a specific account. If I add the Analytics code to the Global Template in a theme, I can use something like:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXX-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('set', {'user_id': '{member="name"}'});
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXXXX-1');
It would return the user_id as the username of the currently logged in user.
However that code does not work if I move it to where it SHOULD go within the Google Analytics code in the Intergrations section. Since that area does not have access to template logic, it obviously does not work.
Is there a way I can return the logged in username via JS?