DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Is there a way to use Tokens in the Page Header Tags under Site Settings? Or an alternate way to add the Username in the header?

Sort:
You are not authorized to post a reply.





New Around Here





    I have some javascript that I want on each page for analytics, but I would like it to include the username of the current user on the page.   The analytics will accept the data in JSON form, and I saw the [User:Username] token in my research, however, it does not render in the Page Header Tags where I have my script.  I've also tried razor and asp code but they simply render and do not execute.  I'm new to DNN so any help would be greatly appreciated. 

    The following is the code that I have tried:

    
     

            <script type=&quot;text/javascript&quot;><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var clicky_custom = clicky_custom || {};<br /><br />             clicky_custom.visitor =
                    username: '[User:Username]',
                };
           
            <script src=&quot;//static.getclicky.com/js&quot; type=&quot;text/javascript&quot;> </script><br />         <script type=&quot;text/javascript&quot;>try { clicky.init(123456789); } catch (e) { }</script></p>

     
     





    Veteran Member





      Yes!

      This is a good place to start: https://stackoverflow.com...e-properties-in-skin

      Without further checking, I think that GetCurrentUserInfo().Username is what you need. In other words ...

      [% =UserController.GetCurrentUserInfo().Username %]

      Replace the square brackets with the usual angled brackets ...
      Joe Craig
      DNN MVP
      Patapsco Research Group





      New Around Here





        Thank you Joe, but in that section, it does not appear to execute server-side code, but rather renders it as text. I'm not familiar enough with how to edit skins or templates directly, which is why I am trying to accomplish this through the settings. Below is a screenshot of my settings:





        Veteran Member





          Posted By GPaul on 04 Nov 2020 03:02 PM

          I have some javascript that I want on each page for analytics, but I would like it to include the username of the current user on the page.   The analytics will accept the data in JSON form, and I saw the [User:Username] token in my research, however, it does not render in the Page Header Tags where I have my script.  I've also tried razor and asp code but they simply render and do not execute.  I'm new to DNN so any help would be greatly appreciated. 

          As you noticed there is no Code / token replace "support" in the Page Header tag field.
          If you want to add this to all your pages, I would suggest adding code to yout Theme / Skin file.
          We have a free skin with a lot of examples: https://demo.40fingers.ne...s-demo-skin/Security

          If that's not what you want, you could use a templatable module like Open Content.
          You don't need to use any of the fancy editing features, it also allows you to just inject a razor file on a page.
          In short:

          - Install Open Content
          - Place the module on a page (this generatres the folder below)
          - In the file system, open Portals/[portalfolder]/OpenContent/Templates
          - Create a folder "Analytics" to hold your razor file
          - Create a template.cshtml file and add this content:
          < script>
          alert("@Dnn.User.Username");
          < /script>

          - Refresh te page where you placed OC and select the newly created file.

           

           






          New Around Here





            you will have to have the token in html then grab it with JavaScript.

            [User:Username]



            <script> <br /> var username; <br /> <br /> window.onload = function() { <br /> username = document.getElementById('TheUserName').innerHTML; <br /> } <br /> <br /> </script>
            You are not authorized to post a reply.

            These Forums are dedicated to the discussion of DNN Platform.

            For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

            1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
            2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
            3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
            4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
            5. No Flaming or Trolling.
            6. No Profanity, Racism, or Prejudice.
            7. Site Moderators have the final word on approving / removing a thread or post or comment.
            8. English language posting only, please.

            Would you like to help us?

            Awesome! Simply post in the forums using the link below and we'll get you started.

            Get Involved