Forum Discussion

BlairPo's avatar
BlairPo
Lithium Alumni (Retired)
13 years ago

Extracting the user and message metadata via JavaScript

Hello,

 

I wanted to confirm the best approach for extracting message and user metadata from a forum page.  This would be done via JavaScript.  The purpose of this is for capturing analytics data.

 

The metadata required is as follows:

 

1.  User rank
2.  Message ID 
3.  Message lifespan

 

I am not sure if I should place a component that makes REST API calls to obtain the values listed above or if it is possible to extract the metadata from the page contents.

 

For example, http://lidemo.lithium.com/t5/Speakers/Amazing-sound-from-my-Xs3/td-p/2713

By checking the Page Source, I see the user rank and message ID in the following markup:

 

<div class="lia-user-rank">Trusted Contributor</div>

 

<input value="2713" id="form_instance_key" name="form_instance_key" type="hidden"></input>

<input class="lia-form-message-uid-key-input" value="2713" id="lia-message_uid_key" name="message_uid_key" type="hidden"></input>

 

Are these reliable areas to use for extracting the data?  Or are these not always consistent.

 

For message lifespan (e.g. "Two weeks ago"), this appears as plain text.  Is there a way to retrieve the message lifespan as a precise data.  It looks like the REST API would work:

http://lidemo.lithium.com/restapi/vc/messages/id/2713/post_time

 

So I would need to add a component which adds this REST API call to the page.  Does this sound like the right approach?

 

 

 

 

 

 

 

  • AdamN's avatar
    AdamN
    Khoros Oracle

    In my opinion, I think it would be much cleaner and more reliable to do this via FreeMarker (supported via the REST API) as opposed to trying to parse out information from the page. With FreeMarker, you can gather the exact pieces of data you need and format in the most appropriate form for your analysis.

     

    I think the most common approach is to dynamically generate the web analytics code via FreeMarker, pulling in the exact information you need directly into the web analytics code. Another option to consider would be to build up a JavaScript object on the fly to store all the information for that page/request, and then reference that object in your analytics code.