Magento 2 increase product views countHow can i get total view count of a product in Magento2?Review Count Added to a Product Tab that Contains Reviews: Breaks the Independent Product Review PageHow can i get total view count of a product in Magento2?How to add category translation programmatically?Migrate Magento 1.9.2.1 to Magento 2.3.0Class MagentoCatalogModelProductAttributeBackendMedia does not existDisable the Sidebar on Product View PageGet recently viewed products excluding particular product ID in Magento 2Magento 2.3 Ajax Breadcrumb Product-DetailGet Product Id On Product PageMagento 2.3 - How to reserve a product in shopping cart and checkout page

(3 of 11: Akari) What is Pyramid Cult's Favorite Car?

What language is Raven using for her attack in the new 52?

Composing fill in the blanks

Self-deportation of American Citizens from US

How can Paypal know my card is being used in another account?

Should I bike or drive to work? (6.8 mi)

Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?

How did the Axis intend to hold the Caucasus?

Compound Word Neologism

Is this photo showing a woman standing in the nude before teenagers real?

Dobbs Murder Mystery : A Picture worth 1000 words?

What are the cons of stateless password generators?

Is it okay for me to decline a project on ethical grounds?

How to efficiently shred a lot of cabbage?

Why is it "on the inside" and not "in the inside"?

Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?

Finding out if upgrading to a newer macOS version will cause issues?

Should I intervene when a colleague in a different department makes students run laps as part of their grade?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

How can I kill my goat?

Must a song using the A minor scale begin or end with an Am chord? If not, how can I tell what the scale is?

Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?

Incrementing add under condition in pandas

Are there any unpublished Iain M. Banks short stories?



Magento 2 increase product views count


How can i get total view count of a product in Magento2?Review Count Added to a Product Tab that Contains Reviews: Breaks the Independent Product Review PageHow can i get total view count of a product in Magento2?How to add category translation programmatically?Migrate Magento 1.9.2.1 to Magento 2.3.0Class MagentoCatalogModelProductAttributeBackendMedia does not existDisable the Sidebar on Product View PageGet recently viewed products excluding particular product ID in Magento 2Magento 2.3 Ajax Breadcrumb Product-DetailGet Product Id On Product PageMagento 2.3 - How to reserve a product in shopping cart and checkout page






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















In Magento 2.3 how to programmatically increase product views count?.
I need it to increase the product views count when the product is viewed on an mobile app.










share|improve this question


























  • refer this link magento.stackexchange.com/questions/127607/…

    – Mohit Rane
    Jul 19 at 5:30











  • Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

    – rajasaravanan28
    Jul 19 at 6:52

















0















In Magento 2.3 how to programmatically increase product views count?.
I need it to increase the product views count when the product is viewed on an mobile app.










share|improve this question


























  • refer this link magento.stackexchange.com/questions/127607/…

    – Mohit Rane
    Jul 19 at 5:30











  • Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

    – rajasaravanan28
    Jul 19 at 6:52













0












0








0








In Magento 2.3 how to programmatically increase product views count?.
I need it to increase the product views count when the product is viewed on an mobile app.










share|improve this question
















In Magento 2.3 how to programmatically increase product views count?.
I need it to increase the product views count when the product is viewed on an mobile app.







magento2.3 product-view






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 at 5:21









Mohit Rane

1,04618 bronze badges




1,04618 bronze badges










asked Jul 19 at 4:31









rajasaravanan28rajasaravanan28

1




1















  • refer this link magento.stackexchange.com/questions/127607/…

    – Mohit Rane
    Jul 19 at 5:30











  • Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

    – rajasaravanan28
    Jul 19 at 6:52

















  • refer this link magento.stackexchange.com/questions/127607/…

    – Mohit Rane
    Jul 19 at 5:30











  • Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

    – rajasaravanan28
    Jul 19 at 6:52
















refer this link magento.stackexchange.com/questions/127607/…

– Mohit Rane
Jul 19 at 5:30





refer this link magento.stackexchange.com/questions/127607/…

– Mohit Rane
Jul 19 at 5:30













Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

– rajasaravanan28
Jul 19 at 6:52





Thanks for your response Mohit. But actually i need to save or increment products view count programmatically when the product is viewed through mobile app.

– rajasaravanan28
Jul 19 at 6:52










1 Answer
1






active

oldest

votes


















0















You can detect mobile device with this code




// Identifying if user is on mobile browser or not
if(preg_match('/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4)))
$browserStatus = 'Mobile';




For product views count, you can use this function




// here $id is product_id
public function getProductCount($id)

/**
* @var MagentoCatalogModelProductInterceptor $product
*/
//Get Object Manager Instance
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
//Load product by product id
$productObj = $objectManager->create('MagentoCatalogModelProduct')->load($id);
$productcollection = $objectManager->create('MagentoReportsModelResourceModelProductCollection');
$productcollection->setProductAttributeSetId($productObj->getAttributeSetId());
$prodData = $productcollection->addViewsCount()->getData();

if (count($prodData) > 0)
foreach ($prodData as $product)
if ($product['entity_id'] == $id)
return (int) $product['views'];




return 0;



Note: Use Dependancies, Object manager is not recommended way.



Hope this helps.






share|improve this answer



























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282589%2fmagento-2-increase-product-views-count%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    You can detect mobile device with this code




    // Identifying if user is on mobile browser or not
    if(preg_match('/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4)))
    $browserStatus = 'Mobile';




    For product views count, you can use this function




    // here $id is product_id
    public function getProductCount($id)

    /**
    * @var MagentoCatalogModelProductInterceptor $product
    */
    //Get Object Manager Instance
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    //Load product by product id
    $productObj = $objectManager->create('MagentoCatalogModelProduct')->load($id);
    $productcollection = $objectManager->create('MagentoReportsModelResourceModelProductCollection');
    $productcollection->setProductAttributeSetId($productObj->getAttributeSetId());
    $prodData = $productcollection->addViewsCount()->getData();

    if (count($prodData) > 0)
    foreach ($prodData as $product)
    if ($product['entity_id'] == $id)
    return (int) $product['views'];




    return 0;



    Note: Use Dependancies, Object manager is not recommended way.



    Hope this helps.






    share|improve this answer





























      0















      You can detect mobile device with this code




      // Identifying if user is on mobile browser or not
      if(preg_match('/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4)))
      $browserStatus = 'Mobile';




      For product views count, you can use this function




      // here $id is product_id
      public function getProductCount($id)

      /**
      * @var MagentoCatalogModelProductInterceptor $product
      */
      //Get Object Manager Instance
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      //Load product by product id
      $productObj = $objectManager->create('MagentoCatalogModelProduct')->load($id);
      $productcollection = $objectManager->create('MagentoReportsModelResourceModelProductCollection');
      $productcollection->setProductAttributeSetId($productObj->getAttributeSetId());
      $prodData = $productcollection->addViewsCount()->getData();

      if (count($prodData) > 0)
      foreach ($prodData as $product)
      if ($product['entity_id'] == $id)
      return (int) $product['views'];




      return 0;



      Note: Use Dependancies, Object manager is not recommended way.



      Hope this helps.






      share|improve this answer



























        0












        0








        0








        You can detect mobile device with this code




        // Identifying if user is on mobile browser or not
        if(preg_match('/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4)))
        $browserStatus = 'Mobile';




        For product views count, you can use this function




        // here $id is product_id
        public function getProductCount($id)

        /**
        * @var MagentoCatalogModelProductInterceptor $product
        */
        //Get Object Manager Instance
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        //Load product by product id
        $productObj = $objectManager->create('MagentoCatalogModelProduct')->load($id);
        $productcollection = $objectManager->create('MagentoReportsModelResourceModelProductCollection');
        $productcollection->setProductAttributeSetId($productObj->getAttributeSetId());
        $prodData = $productcollection->addViewsCount()->getData();

        if (count($prodData) > 0)
        foreach ($prodData as $product)
        if ($product['entity_id'] == $id)
        return (int) $product['views'];




        return 0;



        Note: Use Dependancies, Object manager is not recommended way.



        Hope this helps.






        share|improve this answer














        You can detect mobile device with this code




        // Identifying if user is on mobile browser or not
        if(preg_match('/(android|bbd+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$_SERVER['HTTP_USER_AGENT'])||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i',substr($_SERVER['HTTP_USER_AGENT'],0,4)))
        $browserStatus = 'Mobile';




        For product views count, you can use this function




        // here $id is product_id
        public function getProductCount($id)

        /**
        * @var MagentoCatalogModelProductInterceptor $product
        */
        //Get Object Manager Instance
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
        //Load product by product id
        $productObj = $objectManager->create('MagentoCatalogModelProduct')->load($id);
        $productcollection = $objectManager->create('MagentoReportsModelResourceModelProductCollection');
        $productcollection->setProductAttributeSetId($productObj->getAttributeSetId());
        $prodData = $productcollection->addViewsCount()->getData();

        if (count($prodData) > 0)
        foreach ($prodData as $product)
        if ($product['entity_id'] == $id)
        return (int) $product['views'];




        return 0;



        Note: Use Dependancies, Object manager is not recommended way.



        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 19 at 7:57









        Mohit RaneMohit Rane

        1,04618 bronze badges




        1,04618 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282589%2fmagento-2-increase-product-views-count%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form