Integration with Magento 2

Has anyone successfully gotten Mautic to work on Magento 2, specifically 2.1.5? For page tracking, I can only get the image pixel to work. If I try to use javascript tracking I get a “Fingerprint2 is not define error” (which is discussed in another forum post). I manually added the script as mentioned in the post, but I then get an error about a “define()” function that appears to be a conflict with require.js.



I also have a form that I’m trying to load on a marketing page in my Magento 2 site. If I use the javascript code to display the form, the form appears fine on the page, but clicking the submit button doesn’t do anything. However, if I use the iframe code, the form submits just fine.



I would really like to get the javascript tracking and form working. Does anyone have any ideas on how to fix this or how to troubleshoot? Any help is appreciated.

Has anyone successfully gotten Mautic to work on Magento 2, specifically 2.1.5? For page tracking, I can only get the image pixel to work. If I try to use javascript tracking I get a “Fingerprint2 is not define error” (which is discussed in another forum post). I manually added the script as mentioned in the post, but I then get an error about a “define()” function that appears to be a conflict with require.js.

I also have a form that I’m trying to load on a marketing page in my Magento 2 site. If I use the javascript code to display the form, the form appears fine on the page, but clicking the submit button doesn’t do anything. However, if I use the iframe code, the form submits just fine.

I would really like to get the javascript tracking and form working. Does anyone have any ideas on how to fix this or how to troubleshoot? Any help is appreciated.

I figured out the solution to the problem with mtc.js not loading for site tracking. Since Magento uses RequireJS, I need to use the correct syntax to get RequireJS to load the file. Below is how I was able to get this to work. Also, I’m loading this via Google Tag Manager, but I could also load it in the theme or a plugin module.

<script> require(['//<yourdomain.com/path/to/mtc>/mtc.js'], function(mt){ mt('send', 'pageview'); }); </script>

I’m still working on a solution to the forms not working with the javascript code.

The problem with the forms not working with javascript code was because I had another form on the page that was missing a tag. Chrome was stripping out the tag for the Mautic form, which wouldn’t allow it to validate or submit.

Everything is working now.

Hi madmin27

Hi @mreall,

Thanks for posting your experiences and testings!

I am trying to integrate the tracking script into Magento 2, too, and I am facing the same issue you faced.
Now, I used your snipped with the right format for requireJS; however, the tracking is not working.

I guess that the function, which is integrated in Mautic’s default snipped needs to be added.

Here the default script:

    (function(w,d,t,u,n,a,m){w['MauticTrackingObject']=n;
        w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
        m=d.getElementsByTagName(t)[0];a.async=1;a.src=u;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//<yourdomain.com/path/to/mtc>/mtc.js','mt');

    mt('send', 'pageview');

Have you just integrated your rearranged snipped for requireJS or have you made some other changes additionally?

@Skryption, I’m glad you caught that. I noticed that the Fingerprint2 error went away, but forgot to actually check the tracking to make sure it was working!

I had to dissect the mtc.js code to figure out what was going on and think I found a solution. Try this:

[code][/code]

Because of the way the mtc.js is built in the background, it returns a Fingerprint2 object (fp2) to the ‘require’ call, rather than a Mautic object as I originally assumed. This object needs to be converted to a global object so Mautic can find it when it calls “new Fingerprint2” as part of its tracking functionality.

Mautic’s js is also looking for a window.MauticTrackingObject that contains a function for queuing page actions (i.e. ‘send’, ‘pageview’). The original js tracking code sets this up and our code needs to set it up, too. The code before the call to ‘require’ does this.

I didn’t do extensive testing, but this seems to be working. At least my visits are now being tracked. Let me know if you have any other problems with it.

The code below includes a minified version of the code before the call to ‘require’

<script> (function(w,m){w['MauticTrackingObject']=m;w[m]=w[m]||function(){(w[m].q=w[m].q||[]).push(arguments)}})(window,'mt'); require(['//yourdomain.com/mtc.js'], function(fp2){ window['Fingerprint2'] = fp2; mt('send', 'pageview'); }); </script>

@mreall
Thank you for updating your solution!
Now it seems to work fine, but I have not done any extensive testing yet.

I have just noticed the following error in the console:

XMLHttpRequest cannot load http://yourdomain.com/mtc/event. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://yourdomain.com' is therefore not allowed access.

This error does not seem to be related to the protocol used because it will be displayed no matter if http:// or https:// is used.
Do you receive the same error? I have used a subdomain for Mautic - Might this be the problem?

It is working now!

If mautic domain differs from the website with the tracking script, you need to adjust Mautic CORS Settings in the Backend.
Simply add the domain with your tracking script to the valid domains or disable restricted domains.

Hi @mreall, MageDirect Team has successfully gotten Magento + Mautic Integration!
This integration synchronizes your customers between Magento and Mautic. In this way, you load your customers’ data from the Magento database into the web application – Mautic and perform any needed operations, that are available in Mautic, over this data.
You can download it on our GitHub. Hope it will be useful for you!

Hi @AlexandraS, the documentation says the integration only works with Magento 1.9. Are you also working on an integration with Magento 2.x?