Written by The Jahia Team
   Estimated reading time:

jCustomer includes a web tracker based on the Analytics.JS library that makes it possible to manually integrate tracking into HTML pages or single-page applications. You can find information on how to integrate it in the Unomi documentation.

Tracking Jahia tags, categories and interests with jCustomer’s web tracker

Here is an example of a GraphQL request to retrieve the associated properties on a home page node:

{
  jcr(workspace: LIVE) {
    nodeByPath(path: "/sites/digitall/home") {
      tags : property(name:"j:tagList") {
        values
      }
      interests : property(name:"wem:interests") {
        values 
      }
      categories : property(name:"j:defaultCategory") {
        refNodes {
          path
        }
      }
    }
  }
}

This will produce output similar to this (provided the values have all been properly setup on the content): 

{
  "data": {
    "jcr": {
      "nodeByPath": {
        "tags": {
          "values": [
            "tag1",
            "tag2",
            "tag3"
          ]
        },
        "interests": {
          "values": [
            “interest1:1”,
            “interest2:1”,
            “interest3:2”
          ]
        },
        "categories": {
          "refNodes": [
            {
              "path": "/sites/systemsite/categories/annual-filings"
            },
            {
              "path": "/sites/systemsite/categories/companies/goods"
            },
            {
              "path": "/sites/systemsite/categories/companies/healthcare"
            }
          ]
        }
      }
    }
  }
}

Make sure you upgrade the version of the unomi-tracker to 1.0.5 to make sure the tags/category/interests tracking will work properly.

You can then use these values to feed them to the page view event using the jCustomer tracker: 

<script type="text/javascript">
    // This is an example of how to provide more details page properties to the view event. This can be useful
    // in the case of an SPA that wants to provide information about a view that has metadata such as categories,
    // tags or interests.
    path = location.pathname + location.hash;
    properties = {
        path: path,
        pageInfo: {
            destinationURL: location.href,
            tags : [ "tag1", "tag2", "tag3"],
            categories : ["/sites/systemsite/categories/annual-filings", "/sites/systemsite/categories/companies/goods", "/sites/systemsite/categories/companies/healthcare"],
        },
        interests : {
            "interest1" : 1,
            "interest2" : 1,
            "interest3" : 2
        }
    };
    console.log(properties);
    // this will trigger a second page view for the same page (the first page view is in the tracker snippet).
    window.unomiTracker.page(properties);
</script>

To make sure the values are properly sent to jCustomer, you can connect to it’s SSH shell console using: 

ssh -p 8102 karaf@localhost (default password is karaf)

and use the Event Tail command that will show something like this: 

ID                                  |Type          |Session                             |Profile                             |Timestamp                    |Scope          |Persi|
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
389f9d3a-78ac-4aad-bad9-f2f7523f6040|view          |7cc532cb-4154-8a74-648b-abc9ef64e1f1|48563fd0-6319-4260-8dba-ae421beba26f|Tue Nov 20 21:29:13 CET 2018 |realEstateManag|true |
27223f38-c01c-4d86-ab9e-0ca4ea287a7b|view          |7cc532cb-4154-8a74-648b-abc9ef64e1f1|48563fd0-6319-4260-8dba-ae421beba26f|Tue Nov 20 21:29:13 CET 2018 |realEstateManag|true |

You can then view the events using: 

karaf@root()> event-view 389f9d3a-78ac-4aad-bad9-f2f7523f6040
{
  "itemId" : "389f9d3a-78ac-4aad-bad9-f2f7523f6040",
  "itemType" : "event",
  "scope" : "digitall",
  "version" : 1,
  "eventType" : "view",
  "sessionId" : "7cc532cb-4154-8a74-648b-abc9ef64e1f1",
  "profileId" : "48563fd0-6319-4260-8dba-ae421beba26f",
  "timeStamp" : "2018-11-20T20:29:13Z",
  "properties" : { },
  "source" : {
    "itemId" : "digitall",
    "itemType" : "site",
    "scope" : "digitall",
    "version" : null,
    "properties" : { }
  },
  "target" : {
    "itemId" : "/tracker/#test",
    "itemType" : "page",
    "scope" : "digitall",
    "version" : null,
    "properties" : {
      "attributes" : [ ],
      "consentTypes" : [ ],
      "interests" : {
        "interest1" : 1,
        "interest3" : 3,
        "interest2" : 2
      },
      "pageInfo" : {
        "language" : "en",
        "destinationURL" : "http://localhost:8181/tracker/#test",
        "categories" : [ "category1", "category2", "category3" ],
        "pageID" : "/tracker/#test",
        "pagePath" : "/tracker/#test",
        "pageName" : "Test",
        "tags" : [ "tag1", "tag2", "tag3" ],
        "referringURL" : ""
      }
    }
  },
  "persistent" : true
}

The localhost:8181/tracker test page has also been updated to test this scenario (requires a recent jCustomer build).

If you setup a site with the same scope name as the one being sent to jCustomer (in this example, digital), you can then visualize the page views in the site dashboard as well as the most viewed pages.

Also in the visitors section you should have your test profile that is updated with the tags and interests that you are sending to jCustomer, as in the following examples:

Interests:

profile-interests.png

Tags: 

pages-viewed-by-tags.png