Pull the Report Title into the JavaScript used in a Custom Control Page Module

130 Views Asked by At

I am working on adding the Google Analytics code, to my Cognos reports, to help track usage from our website. I have created a page module custom control that does work correctly when the report page loads. The code currently sets the report name manually in the code. I want to have the control dynamically get the report name. The code for the page module is:

define( ["https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"], function() {

function PageModule()
{};
 
PageModule.prototype.load = function( oPage )
{
 window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX', {
  'page_title' : 'Cognos Report Name'
});
};

I know Cognos has a function that will get the report name when added in a query item. I am trying to get the same report name pulled into the custom control without having to add a unique query item in the report. Is it possible to get the report name using JavaScript, and if so, what code do I need to insert in place of Cognos Report Name? Any suggestions would be greatly appreciated.

1

There are 1 best solutions below

0
On

I received a reply from dougp to my posting, on cognoise, that resolved my problem. Here is the final code which is based on Google Analytics 4.

define( ["https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"], function() {

function PageModule()
{};
 
PageModule.prototype.load = function( oPage )
{

window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX',
  { 'page_title': (new DOMParser()).parseFromString(oPage.application.Document.reportXML, "text/xml").getElementsByTagName("reportName")[0].childNodes[0].nodeValue }
  );