Git Product home page Git Product logo

Comments (4)

KostasMel avatar KostasMel commented on July 4, 2024

I Have the same problem too. when you press the "add to cart" button, it shows the success messages and it disappears almost immediately!

from facebook-for-magento2.

visahardik avatar visahardik commented on July 4, 2024

I have the same problem not only success messages all messages quickly disappear.

from facebook-for-magento2.

aterjung avatar aterjung commented on July 4, 2024

We have the same problem, all messages are removed right after they are displayed. As far as i could see. After disabling the module the messages are displayed as normal again. How to solve this issue? I have allready tried the latest version from main branch.

from facebook-for-magento2.

haelbichalex avatar haelbichalex commented on July 4, 2024

I couldn't yet find out why, but if you use GET instead of POST in the ajax call for ProductInfoForAddToCart, this issue is gone.

https://github.com/facebookincubator/facebook-for-magento2/blob/0da8145b893f7fa7f43e4851bf75b6c304d97317/view/frontend/templates/pixel/add_to_cart.phtml#L37


This call is done here: view/frontend/templates/pixel/add_to_cart.phtml

<?php /** @var \Facebook\BusinessExtension\Block\Pixel\AddToCart $block */ ?>
<?php if ($block->getFacebookPixelID()) { ?>
    <script>
        require([
            'jquery'
        ], function ($) {

            function trackAddToCart(content_ids, content_name, content_category, value, eventId) {
                fbq('set', 'agent', '<?= $block->getFacebookAgentVersion() ?>', '<?= $block->getFacebookPixelID() ?>');
                fbq('track', 'AddToCart', {
                        source: "<?= $block->getSource() ?>",
                        pluginVersion: "<?= $block->getPluginVersion() ?>",
                        content_type: "<?= $block->getContentType() ?>",
                        currency: "<?= $block->getCurrency() ?>",
                        content_ids: content_ids,
                        content_name: content_name,
                        content_category: content_category,
                        value: value
                    },
                    {
                        eventID: eventId
                    }
                );
            }

            var product_info_url = '<?= $block->getProductInfoUrl() ?>';

            $(document).on('ajax:addToCart', function (event, data) {
                var product_sku = data.sku;
                var form_key = jQuery("[name='form_key']").val();
                $.ajax({
                    url: product_info_url,
                    data: {
                        product_sku: product_sku,
                        form_key: form_key
                    },
-                  type: 'post',
+                  type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        trackAddToCart(
                            [res.id],
                            res.name,
                            res.content_category,
                            res.value,
                            res.event_id
                        );
                    }
                });
            });
        });
    </script>
    <?php $block->logEvent($block->getFacebookPixelID(), 'AddToCart') ?>
<?php } ?>

from facebook-for-magento2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.