Like functionality in sharepoint custom aspx page

I want to enable “like” functionality (i.e.) count of likes on custom “aspx ” page created on SharePoint site. Below is the jQuery code for like functionality that I have found.

var likepage = {
    //Likes the current page. 
    LikePage: function () {
        likepage.getUserLikedPage(function(likedPage, likeCount) {

            var aContextObject = new SP.ClientContext();
            EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {
                        _spPageContextInfo.pageListId.substring(1, 37),
                        _spPageContextInfo.pageItemId, !likedPage);

                    function() {
                        var elements = document.getElementsByClassName('likecount');
                        if (likedPage) {
                        } else {
                        for (var i = 0; i < elements.length;i++) {
                            elements[i].innerHTML = likeCount;
                    }, function(sender, args) {
                        // Custom error handling if needed


    // Checks if the user already liked the page, and returns the number of likes. 
    getUserLikedPage: function (cb) {
        var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
        var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
        var item = list.getItemById(_spPageContextInfo.pageItemId);

        context.load(item, "LikedBy", "ID", "LikesCount");
        context.executeQueryAsync(Function.createDelegate(this, function (success) {
            // Check if the user id of the current users is in the collection LikedBy. 
            var $v_0 = item.get_item('LikedBy');
            if (!SP.ScriptHelpers.isNullOrUndefined($v_0)) {
                for (var $v_1 = 0, $v_2 = $v_0.length; $v_1 < $v_2; $v_1++) {
                    var $v_3 = $v_0[$v_1];
                    if ($v_3.$1E_1 === _spPageContextInfo.userId) {
                        cb(true, item.get_item('LikesCount'));
            cb(false, item.get_item('LikesCount'));
            Function.createDelegate(this, function (sender, args) { 
            //Custom error handling if needed 
    initialize: function () {
        var elements = document.getElementsByClassName('likecount');
        likepage.getUserLikedPage(function(likedPage, likesCount) {
            for (var i = 0; i < elements.length; i++) {
                elements[i].innerHTML = likesCount;

The problem here is that I get an error on the following line:

var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);

It gives me following error:

_spPageContextInfo is undefined

After some searching, I found that some libraries need to be imported. So I imported following libraries.

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.runtime.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:FormDigest ID="FormDigest1" runat="server"></SharePoint:FormDigest>

Even after loading these I get above error.
What could be the possible reasons?
Any help would be appreciable.

Like functionality in sharepoint custom aspx page