简体   繁体   中英

Track and limit number of clicks on list item for website per user ajax

I have a list, each of whose item has a button, clicking on which open a dialog to show some information about that perticular item. Now I want to track how many distinct items are clicked by a logged in user. If the number of item unlocked/clicked are greater than a number I should show some other dialog.

I was trying to do it with javascript store API. But facing the issue of attaching the count to user and then binding it to user account.

This is what i was doing

function showMobile(content, phone) {
// store.set('viewed_applied',0);
console.log(store.get('viewed_applied'));
if (store.get('viewed_applied') < 5) {
    $('#modal_body').html(content);
    $('#some_modal').modal('show');
    if (phone !== store.get("phone")) {
        var prev_viewed = store.get('viewed_applied');
        store.set('viewed_applied', prev_viewed + 1);
        store.set("phone", phone);
    }
} else {
    $('#planpricingModal').modal('show');
}

I am calling this function in each click of item button like this

 <div class="pull-right">
        <a class="btn btn-default-nohover" onclick="showMobile('sample_content','some_phone');">show content</a>
    </div

Is there any better way of achieving this using AJAX and backend? Please suggest.

What you need is a database and a table for storing this kind of tracking information per user. You can then use jQuery Ajax for updating or getting the tracking information.

You shouldnt simply showing one or another dialog. Remember that half-smart user can check your source go get content of proper dialog. As answer above - every click in button should call ajax request to backend (for example php). Here you should recognize what content you should show to the user and that content should be returned from backend. Recognizing how many times user already click the button is simple thanks to database for example (or another storage)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM