Can't get article properties from web page | Community
Skip to main content

Can't get article properties from web page

  • July 1, 2024
  • 1 reply
  • 0 views

Marla11

Hello, When I add the following in script.js in the template, user properties are returned:

 var userRole = HelpCenter.user.role;
 console.log(userRole)

and this works:

 var isAdmin = HelpCenter.user.is_admin;
 console.log(isAdmin)
 

But I can't get article properties to return. For example, drawing from this documentation, the following code returns “TypeError: Cannot read properties of undefined (reading 'id')” :

 

 var articleId = HelpCenter.article.id;
 console.log(articleId)

 

and the following code, drawing from this documentation, returns “TypeError: Cannot read properties of undefined (reading 'name')”:

 

 var categoryName = HelpCenter.category.name;
 console.log(categoryName)

 

I use the first two code snippets to send the user role and admin status to custom definitions in Google Analytics 4.

I would like to send the page category to Google Analytics as well.

If there is a better way to send article properties like the page category to Google Analytics, I would be grateful to know.

Thank you for any time.

1 reply

Marla11
  • Author
  • July 8, 2024

I also posted this on Stack Overflow and it was answered there, thank you