Public
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Datalayer for Analytics

Hi, 

Has anyone here recently implemented a datalayer on your community site for analytics? How did you go about creating your datalayer and how did you add it to your community site? 

10 Replies 10
Executive

I created a relatively basic datalayer that a couple of our analytics platforms are able to use. It's a javascript-based component that is added to the page header. There are some extras there that we aren't using right now (like Category), and I've shared the contents of the component below.

custom-analytics-data-layer_js


<#import "custom.common-helper" as commonHelper >
<script type="text/javascript">
<#if user.anonymous>
<#assign user_sso_id = "Anonymous">
<#assign user_type = "" />
window.username;
<#else>
<#assign user_sso_id = 'SSO_Missing'/>
<#assign query = "SELECT sso_id FROM users where id='${user.id}'"/>
<#assign SSORes = restadmin("2.0","/search?q=" + query?url) />
<#if SSORes?? && SSORes.data?? && SSORes.data.items?? && SSORes.data.items?size gt 0 && SSORes.data.items[0].sso_id??>
<#assign user_sso_id = SSORes.data.items[0].sso_id/>
</#if>
<#assign window_username = user_sso_id>
<#assign user_type = commonHelper.getUserType(user.id) />
window.username = "${window_username}";
</#if>
var digitalData =
{
"page": {
"pageInfo": {
"pageName": document.title
},
"category": {
"primaryCategory": "",
}
},
"user": {
"userType": "${user_type}",
"userId": "${user.id?c}",
"loginId" : "${user.login}",
"sso_id" : "${user_sso_id}"
}
};
window.digitalData = digitalData;
window.userType = digitalData.user.userType;
</script>

commonHelper is used to get the userType (employee/partner/customer/guest/etc. based on roles and might not be relevant for you.

I'm curious what others might be doing here that we could or should add.

EDIT: Sorry the formatting didn't paste in here. Can share as a txt file if desired.

---
Community Manager \\ NetApp
Moderator

Hi jennychiu1nyp, and Drew_C, Hope you are doing well!!

Did you know our community already has a built-in data layer? The below link should be helpful. First step should be to consume it. However, be aware of the potential risks and take caution when deploying web analytics tools to the community to avoid any performance degradation.

https://developer.khoros.com/khoroscommunitydevdocs/docs/web-tracking-with-lithiumcommunityjsonobjec...

 



That's an important call-out, @SyedSa. I did know about this. The information I'm adding isn't available in the standard data layer, like the SSO ID and the User Type, for example. A couple of items are duplicated, but that's done in order to fit the structure our application is looking for.

---
Community Manager \\ NetApp
Moderator

JFYI, using SSO ID is not advisable as it includes identifying information in analytics, as analytics technologies are often used in conjunction with advertising technologies. 

In a worst-case scenario, you can create a custom component to insert any desired information into the page load.

Fair point. The analytics scripting doesn't run unless users opt-in with our OneTrust implementation. So, while its present in a JS variable, it isn't extracted nor is it forwarded.

---
Community Manager \\ NetApp
Moderator

It sounds like you have implemented a strong privacy-by-design approach, by having the analytics script only runs when the user opts in and not extracting or forwarding data even if the script is running. This is a good way to ensure that the user's data is protected.

Hi, 

Me again! I'm not a superbly technical person but I did read this article and if I'm understanding it correctly, even though the LITHIUM.CommunityJsonObject is already on the page (I can see it in Inspect > Console) , I still need to put in some javascript into the Studio > Community Style > Wrapper > Page Hitbox to identify the information I want to use in my Google Tag Manager?

Hi @jennychiu1nyp

Do you have GTM in the hitbox already?
If the data is in the CommunityJsonObject, you can configure Google Analytics, or your analytics too, in GTM to consume it without changing the hitbox code. That's why companies use GTM to deploy website analytics tools – so that they don't need to keep adding javascript to the site.

This is something that the customer can own using a 3rd party product. Be warned, however, that if people use website analytics tools badly, it can impact website (Community) performance. 


However, if you come across performance problems, the first thing to try is loading without your analytics tools.

Thanks @SyedSa ! I do have GTM in the my hitbox. The part where I am stuck at is knowing how to configure GTM to read the CommunityJsonObject. I am very familiar with Google's “dataLayer.push” but I have no idea how to tell GTM to read from a different data layer.  Any pointers would be appreciated! 

You are welcome @jennychiu1nyp

Welcome to the Technology board!

Curious about our platform? Looking to connect on social technology? You've come to the right place!

Are you a Khoros customer? For direct assistance from our Support team, please visit the Support Forum.