Support » Plugin: WP Mautic » wpmautic_send() does not execute

  • Hello.

    I’m trying to execute the wpmautic_send() function when a user accepts cookies but I get a “WPMautic: mt not defined. Did you load mtc.js ?” error in the console. I’m a total beginner with javascript and wonder what I’m doing wrong.

    Here is the code I’m executing when a user accepts cookies:

    <script type="text/javascript" src="https://mywebsite.com/mautic/mtc.js"></script>
    
    <script type="text/javascript">
    wpmautic_send();
    </script>

    When I enter the mtc.js file url directly into the browser, the file contents load ok, so the file is there.

    I appreciate any help since I can’t find anything on Google.

    • This topic was modified 8 months, 1 week ago by songee.
    • This topic was modified 8 months, 1 week ago by songee.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author shulard

    (@shulard)

    Hello !

    If the error message appears, it’s because the Mautic JavaScript API wasn’t loaded properly. Can you check in the network tab of your browser console if everything is loaded ?

    I don’t see anything strange in your code here…

    Thread Starter songee

    (@songee)

    Thank you for lending me a hand, shulard!

    I’ve checked the network tab and the only Mautic related JS files that are loaded are generate.js and mautic-form.js.

    I’m running an nginx webserver and previously had a problem where loading https://mywebsite.com/mautic/mtc.js resulted in 404 error and I had to load it via https://mywebsite.com/mautic/index.php/mtc.js for it to work.

    I made the following changes in the server bock of my nginx configuration file to make it load without the index.php in the link:

    location /mautic/ {                                                                                                                                                
            try_files $uri $uri/ /mautic/index.php$is_args$args;                                                                 
                                                                                                              
            location ~ \.php {                                                                                
                    include snippets/fastcgi-php.conf;                                                        
                    fastcgi_pass unix:/run/php/php7.3-fpm.sock;                                               
                    include /etc/nginx/my_includes/fastcgi_optimize.conf;                                     
            }                                                                                                 
    }                                                                                                         
    
    location = /mautic/mtc.js {                                    
            expires off;                                           
            default_type "application/javascript";                 
            try_files $uri $uri/ /mautic/index.php$is_args$args;   
    }                                                              
                                                                   
    location = /mautic/form/generate.js {                          
            expires off;                                           
            default_type "application/javascript";                 
            try_files $uri $uri/ /mautic/index.php$is_args$args;   
    }

    I think there may be a problem with the way nginx is configured on my end since I’m executing wpmautic_send() correctly?

    Also, the network tab shows that generate.js file is being loaded from the URL https://mywebsite.com/mautic/index.php/form/generate.js?id=6 with the index.php in the link.

    • This reply was modified 8 months, 1 week ago by songee.
    Plugin Author shulard

    (@shulard)

    Hello !

    The index.php can be a bit annoying in the webserver configuration but must not cause issue on the frontend when loading components. If you can load forms, the tracker can also be loaded.

    Can you share an URL where I can take a look directly in the website ? Also what’s the configured Mautic URL in the plugin setting page ? And which option did you chose to load the tracker ?

    Thread Starter songee

    (@songee)

    Of course. Here is the website: https://polynook.com

    And the WP Mautic plugin settings: https://imgur.com/a/VQoxJzM

    I checked the network tab again and it seems that the mtc.js is indeed loaded when cookies are accepted, but the error is still there and Mautic tracking cookies don’t get set.

    Thread Starter songee

    (@songee)

    Hi @shulard.

    I wonder if there are any news about the issue?

    Plugin Author shulard

    (@shulard)

    Hello !

    Sorry for the late reply, I just took a look and it seems that your webpage fail to load the mtc.js file.

    After accepting cookies, I got the following error in the browser console :

    
    Uncaught Error: Error: remote script failed https://polynook.com/mautic/mtc.js - https://polynook.com/wp-content/cache/autoptimize/js/autoptimize_61563aeb45d3843260000b040dd669cc.js: 2
    

    I don’t know how to solve it, the mtc.js file is accessible and valid. Maybe it’s related to some others plugins you use ?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.