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="text/javascript"><br /> var clicky_custom = clicky_custom || {};<br /><br /> clicky_custom.visitor = username: '[User:Username]', }; <script src="//static.getclicky.com/js" type="text/javascript"> </script><br /> <script type="text/javascript">try { clicky.init(123456789); } catch (e) { }</script></p>
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.
< script> alert("@Dnn.User.Username"); < /script>
[User:Username]
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:
Awesome! Simply post in the forums using the link below and we'll get you started.