Analytics

Onegini IDP has placeholders to insert analytics script tags in the <head> section of the HTML. This can be done via a custom template, via the admin console, or a combination of both. The placeholders can also be used to insert other kind of scripts (surveys, feedback, customer care chat) or additional CSS files.

User information is exposed via the following methods in JavaScript:

  • onegini.pageData.isPersonLoggedIn() is true if the user is logged in
  • onegini.pageData.getPersonId() returns the identifier of the logged in user, or null if the user is not logged in

Custom template

This method can be used if the content is the same for all environments and the content is not changing frequently.

Create a Thymeleaf template fragment_analytics.html and place it in src/main/webapp/WEB-INF/templates/personal. Create a Thymeleaf fragment analytics_head inside this template with the custom content.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Fragment that can be overridden to place analytics tag in the head</title>
    <th:block th:fragment="analytics_head">
        <!-- Insert your custom HTML here. 
        Please note that it must be valid XML (CDATA can be used for inline JavaScript) -->
        <script src="//example.com/my_analytics.js"></script>
        <script>
            /*<![CDATA[*/
            if (myAnalytics && onegini.pageData.isPersonLoggedIn()) {
              myAnalytics.user_id = onegini.pageData.getPersonId(); 
            }
            /*]]>*/
        </script>
    </th:block>
</head>
<body>
</body>
</html>

Admin console

This method can be used if the content is different for each environment or if the content is changing frequently.

An administrator can configure this content via the admin console. This content will be loaded at the end of the <head>, after the custom template.