How to use is_user_logged_in() to send a dataLayer push
-
Hi everyone,
I am desperately trying for 4 days in a row to solve an issue but since my coding understanding is limited, I am stuck.
Basically what I want to do is read from wordpress’s is_user_logged_in() function, and then based on the value I get retured, peform a certain operation.
The issue is, I am always getting value returned 1, even when I’m not logged in (Tried even a fresh browser). I’m so far using the following JS script:
<script> if ('<?php echo is_user_logged_in(); ?>') { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'userLoggedIn' : '1' }); } else{ window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'userLoggedIn' : '0' }); } </script>
Any clues what i’m doing wrong?
Worth to mention: I’m adding this code to the elementor code blocks, which promissed to execute this code in the <head> (based on my selection).
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to use is_user_logged_in() to send a dataLayer push’ is closed to new replies.