Skip to main content
Frank
Product Guru
August 22, 2019
Tutorial

How to create dynamic community content using the inSidedData object

  • August 22, 2019
  • 35 replies
  • 3948 views

What is the inSidedData object?


The inSidedData object is a powerful dynamic front end element that can be used to return lots of information about a particular community page or user. Lets explore the object in more detail and then see how it can be used:

Looking into the top level properties of the object on this community:

insidedData.communityId: "gainsight-us"
insidedData.device: "desktop"
inSidedData.environment: "production"
inSidedData.language: "en"


Within the inSidedData object are a number of nested objects that dynamically provide much more detail on the page you are on, lets dive into the objects for this community:

inSidedData.content {
category: {
id: 38,
title: "Got a question?"
}
path: "Got a question?:Tips for self diagnosing platform issues"
post: {
id: null
}
topic: {
id: 1672,
title: "Tips for self diagnosing platform issues",
type: "discussion",
created: 1564131222,
replies: 0
}
}
inSidedData.form {
name: "",
step: ""
}
inSidedData.page {
firstRender: false name: "Search: "
roadmap ""
pageNumber: 1,
name: "Search: "
roadmap "",
path: "inSpired:Search:Search: "
roadmap "",
section: "Search",
site: "inSpired"
}
insidedData.search {
phrase: "roadmap",
count: 62
}
inSidedData.user {
userid: "571",
rank: "1",
role: "roles.administrator, inSided",
name: "Frank"
}

 

Now this is just a very brief overview of the inSidedData object - feel free to explore the object in more detail by opening the console in your web browser and typing in 'inSidedData' and hitting return!

 

 

Ok this is great but what can I use this for?


We've created these quick examples to show you how to dynamically configure content in your community. Lets create a dynamic widget asking unregistered users to create a community profile and engage with other users. This widget will only show up :

HTML code - create a new HTML Block widget add this code to the newly created widget (make sure not to fill out the title as we're going to create the title in the widget itself):
 

<div id="register-side-widget" class="" style="display:none;">
<h4 class="h4">Register now</h4>
<div class="html">
<a href="/member/register" class="btn--cta btn--new-topic qa-topic-new-button">Make an account now!</a>
</div>
</div>



JS scripts (relies on jQuery to unhide the widget):
1. Only show the widget for non logged in users, any one logged in will not see it

<script> 
if (inSidedData.user.role == 'roles.guest') {
// Make the widget visible
$('#register-side-widget').removeClass().removeAttr('style');
}
</script>


2. Only show the widget for a certain topic

<script> 
if (inSidedData.content.topic.id == 1701) {
// Make the widget visible
$('#register-side-widget').removeClass().removeAttr('style');
}
</script>


3. Only show the widget for topics within certain categories

<script> 
if (inSidedData.content.category.id == 117) {
// Make the widget visible
$('#register-side-widget')
.removeClass()
.removeAttr('style');
}
</script>


4. Only show the widget for mobile users on topics created within the last 24 hours

<script>
var hours = 24;
if (inSidedData.content.topic.created != null) {
if ((inSidedData.content.topic.created > (Date.now() + hours * 60 * 60 * 1000) / 1000) && inSidedData.device == 'mobile') {
// Make the widget visible
$('#register-side-widget').removeClass().removeAttr('style');
}
}
</script>


This is just a small sample of what is possible (we will constantly be updating this page and adding more). Alternatively if you don't want to use CSS to show/hide content, you can inject the content into the page instead - just create a unique HTML element in a widget and then use .append() or .html() to inject the markup. Also please note that the inSidedData object can only be used in the last code panel of the third party scripts page - this is because it is only initialised towards at the end of page load.

Happy coding!

 

 

35 replies

mstone
Helper ⭐️
May 25, 2020

This is very cool. @Frank is there any way to access custom fields on a user profile from the insidedData.user object? It looks like the data within that object is limited to:

{

	userid: "571",  	rank: "1",  	role: "roles.administrator, 	inSided",  	name: "Frank"

}

 

Thanks!

Mike

tom.shaddock
Gainsight Employee ⭐️⭐️
May 27, 2020

Hi @mstone yep you are correct in that the user object in the wider inSidedData object doesn’t contain the custom profile fields. Its limited to just the fields you posted above - im wondering though can you describe your use case for it? Would you be able to achieve what you wanted via the setting of a custom role, as this is retrievable via the inSidedData object? These custom roles could even be assigned to users on an automated basis if the ranking system is used to assign them.

Let me know though, am happy to help out!

mstone
Helper ⭐️
May 27, 2020

Hey Tom, thanks for the response. We would like to pass custom fields into the InSided user profile so that we can present the user with account information when they login. For example -- we are commonly asked by customers who their customer success manager is. If we could expose this ‘customer success manager’ information within the insidedData object then we’d be able to display it on the page as described above. 

tom.shaddock
Gainsight Employee ⭐️⭐️
May 29, 2020

Hi @mstone  great use case! The only way you’d be able to retrieve the custom profile fields is to to make an api call. In theory you could grab the user id from the inSidedData object, make a call and then render the result on screen. However I do realise this is quite a lot of effort for only a small alteration for the front end, but im not sure of the complexity of adding this to the inSidedData object - @Yoeri perhaps we can perform a small investigation internally to see if this is a quick win? :grin:

tom.shaddock
Gainsight Employee ⭐️⭐️
June 3, 2020

Hi @mstone so i’ve actually just realised the custom profile fields can be read from the front end - if you append something like: /member/memberProfile?memberId=149 after your community URL, you’ll see you get a JSON object of the user profile, which also includes the custom profile fields you set up. You could in theory use an ajax request via javascript in a third party script to get this information and then render on screen. You might be able to achieve what you need to straight away using this method, let me know if anything doesnt make sense!

aluciani
Helper ⭐️
June 3, 2020

Some nice options here, I am not a dev person so a little cautious if I decide to apply to my community. Might be helpful to have some short tutorial videos to helps folks like me who are considering applying these :slight_smile:

mstone
Helper ⭐️
June 4, 2020

Hey @tom.shaddock I messed around with this a bit and it looks like it could work! One thing I noticed was that only ‘Public’  profile fields are made available on the front end. In my case the ‘Customer Success Field’ fields is a ‘Private’ field (only visible to user & moderators) and doesn’t appear in the object. Any thoughts on how we’d be able to make it available without making it ‘Public’?

tom.shaddock
Gainsight Employee ⭐️⭐️
June 10, 2020

Hey @mstone hmm unfortunately only the public profile fields will be displayed here (or any where on the public front end) - is there any possibility to make this a public field instead?

If this is not possible - then a workaround I can think of would be to make this profile field public, then to apply a new HTML class/id to this public profile field (just this one and no other). You could then in theory just apply a CSS rule to hide this on the profile page if you don’t want it to be displayed there, or/and apply a javascript rule to remove this element from the page on load (via the third party scripts part of the control backend).

I think this way should be able to get you the result you want - but its just a thought off the top of my head though :)

mstone
Helper ⭐️
June 10, 2020

That makes sense, I’ll give that a shot. Thanks @tom.shaddock 

timcavey
Helper ⭐️⭐️
March 9, 2021

I have a couple of related questions @Frank or anyone else:

 

  1. Does Insided allow for custom HTML to be inserted anywhere for example allowing banner ads to be used?
  2. If we can insert things like banner ads, would the methods outlined above be the best way to segment and target these at certain audiences? 

 

learning, sharing and repeat