I'm trying to check if the user is logged in or not (in the header of the page), so I can decide if I count that user in Google Analytics or not. All I need is a true or false (0/1) from that function, but I am not sure how to properly call it within JS.
You can ignore the part within the IF blocks, it's just a dataLayer push so I can later use the value for triggering the Google Analytics tags accordingly.
So far I tried these options but without luck:
var logintemp=0;
logintemp=<?php echo is_user_logged_in() ?> ;
if (logintemp) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'userLoggedIn' : '1'
});}
else {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'userLoggedIn' : '0'
});}
</script>
<script type="text/javascript">
if ('<?php is_user_logged_in(); ?>') {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'userLoggedIn' : '1'
});}
else {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'userLoggedIn' : '0'
});}
</script>```