• Resolved Abdul Azij

    (@viraltui)


    i have successfully setup One tap Sign in with Google+Sign in with Google button on all pages.

    it’s working fine as expected.

    however, i have a custom page template, in which One tap Sign in with Google isn’t showing up. but if i changes to default template it shows up.

    context of the template is that, if a visitor is logged in then they are told to update their profile (my site users). for non-logged-in user they see messages to login/image with loging/registration url linked.

    Most importantly i used Gemini to create/debug the custom template, and there is possibility that do not keep traditional WordPress header/footer from Astra theme. even though my template has these code:

    and end with:

    <?php
    // Template Name: Update Contact Info

    get_header();

    if (!is_user_logged_in()) {
    // Display login prompt and message for non-logged-in users

    // messages+other necessary codes

    get_footer();
    ?>

    what is the problem?

    could it be that site kit plugins isn’t loading on that custom template/ page?

    • This topic was modified 1 month, 2 weeks ago by Abdul Azij. Reason: add details where not working

    The page I need help with: [log in to see the link]

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter Abdul Azij

    (@viraltui)

    one question that has been bugging me for some time. console.log (F12) gives this error:

    Uncaught ReferenceError: google is not defined
    at 10d93dc397bb6d8364f2defff7230c2f.js?ver=a9888:16:351
    at 10d93dc397bb6d8364f2defff7230c2f.js?ver=a9888:16:556

    upon checking and searching js file, i can see that:

    ;(()=>{async function handleCredentialResponse(response){try{const res=await fetch('https://www.viraltui.com/wp-login.php?action=googlesitekit_auth',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams(response)});if(res.ok&&res.redirected){location.assign(res.url)}}catch(error){console.error(error)}}google.accounts.id.initialize({client_id:'7myownid.apps.googleusercontent.com',callback:handleCredentialResponse,library_name:'Site-Kit'});google.accounts.id.prompt()})()

    could it be that My LiteSpeed Cache Plugin is compressing all .JS including Site kit required .JS file as well.

    Plugin Support Adam Dunnage

    (@adamdunnage)

    @viraltui Thanks for sharing the console error, I will check this. With regards to the LiteSpeed Cache Plugin, we have seen issues with this plugin and other optimization plugins specifically when using JS minification. If you have this setting enabled you could try disabling it temporary and checking your site once more?

    You can also try disabling the plugin altogether and checking your site once more for the one tap prompt on your site pages.

    Thread Starter Abdul Azij

    (@viraltui)

    i don’t know why but i have this error lot’s time:

    [30-Jan-2025 03:15:49 UTC] PHP Warning:  Undefined array key "family_name" in /home/vv/public_html/wp-content/plugins/google-site-kit/includes/Modules/Sign_In_With_Google/Authenticator.php on line 261

    also, i forgot to mention that i use Wordfence Free version.

    Plugin Support Adam Dunnage

    (@adamdunnage)

    @viraltui Thanks for sharing. I will discuss this with the team to explore what may be happening here and get back to you once I have an update. If you have any other information in the meantime then let me know here.

    Plugin Support Adam Dunnage

    (@adamdunnage)

    @viraltui I have discussed this with the team and they have asked if you could when possible and you’re back to share a recording of your experience with any console errors you may see at the time. I will await this information from you and continue to monitor this. Should I have an update before you make contact I will let you know here.

    Thread Starter Abdul Azij

    (@viraltui)

    well i have been testing things my self.

    here is the code that made my custom page Template Pages to show one tap sign in:

    <!-- Sign in with Google button added by Site Kit -->
    <script src="https://accounts.google.com/gsi/client"></script>
    <script>
    (()=>{async function handleCredentialResponse(response){try{const res=await fetch('https://www.viraltui.com/wp-login.php?action=googlesitekit_auth',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:new URLSearchParams(response)});if(res.ok && res.redirected){location.assign(res.url);}}catch(error){console.error(error);}}google.accounts.id.initialize({client_id:'mysecretzzzzzzzzid.apps.googleusercontent.com',callback:handleCredentialResponse,library_name:'Site-Kit'});google.accounts.id.prompt();})();
    </script>

    <!-- End Sign in with Google button added by Site Kit -->

    this code does let user login/sign up, but after login they redirect to /wp-admin/ instead of redirecting to the page where user login.

    can you tell me if this code is all right to use?

    Most importantly can you modify the code to redirect to same page where login occurred?

    As for Recording, iam hoping i will be able to give that on Sunday (2nd February).

    Thread Starter Abdul Azij

    (@viraltui)

    I had to use ChatGPT, Gemini is useless (I’m a text-based AI, and that is outside of my capabilities.)

    here is the code now it’s working perfectly.

    <!-- Sign in with Google button added by Site Kit -->
    <script src="https://accounts.google.com/gsi/client"></script>
    <script>
    (() => {
    // Store the current page URL
    const currentPage = window.location.href;

    async function handleCredentialResponse(response) {
    try {
    // Append the return URL as a query parameter
    const params = new URLSearchParams(response);
    params.append('redirect_to', currentPage);

    const res = await fetch('https://www.viraltui.com/wp-login.php?action=googlesitekit_auth', {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: params
    });

    if (res.ok && res.redirected) {
    location.assign(res.url);
    }
    } catch (error) {
    console.error(error);
    }
    }

    google.accounts.id.initialize({
    client_id: '7secretid.apps.googleusercontent.com',
    callback: handleCredentialResponse,
    library_name: 'Site-Kit'
    });

    google.accounts.id.prompt();
    })();
    </script>
    <!-- End Sign in with Google button added by Site Kit -->

    Thank you for trying to help.

    Thread Starter Abdul Azij

    (@viraltui)

    but even if user is logged-in it still show One tap Prompts.

    Thread Starter Abdul Azij

    (@viraltui)

    all right i had to add some code in functions.php now everything is going well.

Viewing 9 replies - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.