Wednesday, June 26, 2013

Detection of first time visitor to the website using jquery.

Hi guys,


Today I was working with one requirement, in which I would find the first time visitor to my portal/website(I am using Liferay portal for website) for some business needs. Lets say to Wish like welcome note with beautiful picture or like asking user to agree terms and condition before going opening website, etc, etc.... I think most of the time we need this feature. Hence I am writing this posts, may be useful for somebody.


HOW TO DETECT FIRST TIME VISITOR TO THE WEBSITE???????

If we are using any web technologies or I would say smart frameworks like LIFERAY, we can make use of Jquery code to detect. So how???? Lets see how we can do in Liferay using themes, using Jquery in it. 

  • If you are using your custom theme, you can add the jquery code in main.js file. Which you can find in <theme-name>/docroot/_diffs/js/main.js
  • lets write jquery code, we can make use of cookies.
            lets give the cookie name to your site as  "myCookie", lets set the cookie name.
           
 if(!($.cookie('myCookie')))
  {
      alert("Welcome, Thanks for visiting");
      $.cookie('myCookie','visited', { path: '/', expires: 10000 });
  }
else
 {
     alert("Already visited.");
 }
That's all guys. Use the above code in main.js of your theme and you can detect the first time visitor.
IMPORTANT NOTES 
  1. To work with cookies of Jquery you should have the jquery.cookie.js plugin. You can find that in   jquery.cookie.js
  2. If you want to know more about attributes I have used for cookies you can go through Cookies Properties



Friday, October 19, 2012

Adding custom field in registration page is Liferay

Hi, guys Liferay is such a beautiful portal technology, it has one pretty nice feature about custom fields.

This post is how to use that custom field feature in registration field in liferay

Here are the steps to be followed
1. Click on control panel > User > Custom attributes > Add Custom attributes.

2. Here we need to give a key (name) and type of the field.  

3. For eg. We will have an Field called Designation added which is a text field. 
    Key :   Designation
    Type : Text-field(Indexed) and save. 

4. Then add the custom attribute taglib in the create_account.jsp in /tomcat/webapps/ROOT/html/portlet/login as follows:

<liferay-ui:custom-attribute-list

            className="com.liferay.portal.model.User"

            classPK="<%= 0l %>"

            editable="<%= true %>"

            label="<%= true %>"

      /> 
    But this field will not appear on the create account page because permissions are not given.


   Hence to permission click on action tab of that custom attribute(here eg.Designation) and permissions

 Note: very important thing is assigning permission for added custom field to guest

    1. Here for guest we give permission for view and update.
  
    2. Now in the create account page this field will appear.


And you can get those value in expando table in liferay, you can fetch the value using expandoBridge class.