# Integration with Magento 2

**URL:** <https://forum.mautic.org/t/integration-with-magento-2/8225>\
**Category:** Product Support\
**Created:** [April 17, 2017, 3:42pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225 "2017-04-17T15:42:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [April 17, 2017, 3:42pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/1 "2017-04-17T15:42:02Z")

</div>

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](https://www.mautic.org/community/index.php/6453-uncaught-referenceerror-fingerprint2-is-not-defined)). 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.

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [April 17, 2017, 3:42pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/2 "2017-04-17T15:42:02Z")

</div>

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](https://www.mautic.org/community/index.php/6453-uncaught-referenceerror-fingerprint2-is-not-defined)). 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.

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [April 18, 2017, 9:52pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/3 "2017-04-18T21:52:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [April 21, 2017, 11:56pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/4 "2017-04-21T23:56:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Skryption](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Skryption](https://forum.mautic.org/u/Skryption)\
**Post date:** [May 6, 2017, 11:02am UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/5 "2017-05-06T11:02:32Z")

</div>

Hi madmin27

---

<div class="post-metadata">

**Author:** ![Skryption](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Skryption](https://forum.mautic.org/u/Skryption)\
**Post date:** [May 6, 2017, 11:08am UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/6 "2017-05-06T11:08:42Z")

</div>

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:

```auto
    (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?

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [May 6, 2017, 9:49pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/7 "2017-05-06T21:49:19Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [May 6, 2017, 9:59pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/8 "2017-05-06T21:59:08Z")

</div>

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>`

---

<div class="post-metadata">

**Author:** ![Skryption](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Skryption](https://forum.mautic.org/u/Skryption)\
**Post date:** [May 8, 2017, 5:57pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/9 "2017-05-08T17:57:40Z")

</div>

@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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![Skryption](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Skryption](https://forum.mautic.org/u/Skryption)\
**Post date:** [May 9, 2017, 11:12am UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/10 "2017-05-09T11:12:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AlexandraS](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@AlexandraS](https://forum.mautic.org/u/AlexandraS)\
**Post date:** [September 16, 2017, 7:34am UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/11 "2017-09-16T07:34:00Z")

</div>

Hi @mreall, MageDirect Team has successfully gotten [Magento + Mautic Integration](https://magedirect.co/solutions/magento-mautic/)!  
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!

---

<div class="post-metadata">

**Author:** ![mreall](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mreall](https://forum.mautic.org/u/mreall)\
**Post date:** [September 16, 2017, 10:32pm UTC](https://forum.mautic.org/t/integration-with-magento-2/8225/12 "2017-09-16T22:32:34Z")

</div>

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