# Mtc.js, ip address, uniqueness questions

**URL:** <https://forum.mautic.org/t/mtc-js-ip-address-uniqueness-questions/20632>\
**Category:** Product Support\
**Created:** [August 29, 2021, 7:25pm UTC](https://forum.mautic.org/t/mtc-js-ip-address-uniqueness-questions/20632 "2021-08-29T19:25:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![donbowman](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/donbowman/32/5702_2.png) [@donbowman](https://forum.mautic.org/u/donbowman)\
**Post date:** [August 29, 2021, 7:25pm UTC](https://forum.mautic.org/t/mtc-js-ip-address-uniqueness-questions/20632/1 "2021-08-29T19:25:54Z")

</div>

**Your software**  
My Mautic version is: 4.0.0-features  
My PHP version is: 7.4  
My Database type and version is: tidb

I don’t believe this is working as intended, but want to ask to make sure.

I am using mtc.js tracking. I find i end up with a lot of duplicates.  
First, I end up with duplicate IP addresses:

```auto
m> select * from ip_addresses where id in ('159','204','30183','60190','60191');
+-------+---------------+----------------+
| id | ip_address | ip_details |                                                                                                                                                                                                                                                  
+-------+---------------+----------------+
| 159 | XX9.205.64.16 | a:10:{s:4:...} |
| 204 | XX9.205.64.16 | a:10:{s:4:...} |
| 30183 | XX9.205.64.16 | a:10:{s:4:...} |
| 60190 | XX9.205.64.16 | a:10:{s:4:...} |
| 60191 | XX9.205.64.16 | a:10:{s:4:...} |
+-------+---------------+----------------+

```

Then I find that the same lead is attached over and over to these:

```auto
> select * from lead_ips_xref where lead_id = 60316;
+---------+-------+
| lead_id | ip_id |
+---------+-------+
| 60316 | 159 |
| 60316 | 204 |
| 60316 | 30183 |
| 60316 | 60190 |
| 60316 | 60191 |
+---------+-------+

```

And, i find that the Lead has been created multiple times:

```auto
> select email,firstname from leads where id in (633, 60316);
+---------------------------+-----------+
| email | firstname |
+---------------------------+-----------+
| NULL | NULL |
| USER@Domain | Name |
+---------------------------+-----------+

```

I was of the understanding that `Identify visitors by IP ` (which I have enabled) would cause these to be merged together instead of created separate.

I seems [Fix #7559: Merge lead devices when merging leads (3.x rebase of #7561) by pjeby · Pull Request #8836 · mautic/ma](https://github.com/mautic/mautic/pull/8836) was created to solve this, but does not for mtc.js.

Am I understanding this correctly? I think the intent is:

1. user interacts w/ mtc.js, contact id created
2. user interacts w/ some form etc, gives email, contact id is updated
3. user opens new device, interacts w/ mtc.js, contact id is updated

Instead i see a new contact id for each of the 3 above.

It seems, in ContactTracker.php, that we must have _both_ ‘track\_contact\_by\_ip’ and ‘anonymize\_ip’, is that correct?

```auto
        if ($this->coreParametersHelper->get('track_contact_by_ip') && $this->coreParametersHelper->get('anonymize_ip')) {
            /** @var Lead[] $leads */
            $leads = $this->leadRepository->getLeadsByIp($ip->getIpAddress());
            if (count($leads)) {
                $lead = $leads[0];
                $this->logger->addDebug("CONTACT: Existing lead found with ID# {$lead->getId()}.");

                return $lead;
            }
        }

```

Comments?

I created PR

> <https://github.com/mautic/mautic/pull/10380>
>
> see https://forum.mautic.org/t/mtc-js-ip-address-uniqueness-questions/20632
> 
> |… Q | A
> | -------------------------------------- | ---
> | Branch? | "features" for all features, enhancements and bug fixes (until 3.3.0 is released) 
> | Bug fix? | yes
> | New feature? | no
> | Deprecations? | no
> | BC breaks? | no
> | Automated tests included? | no
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation#... 
> | Issue(s) addressed | Fixes #... 
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#step-5-work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "features" branch.
> \--\>
> 
> See https://forum.mautic.org/t/mtc-js-ip-address-uniqueness-questions/20632 for a discussion.
> 
> In the mtc.js tracker, the intent is to lookup the contact by IP \*except\* if anonymised. 
> Instead, it was and'ing the two.
> 
> \#### Description:
> 
> 
> \#### Steps to test this PR:
> Setup site using mtc.js tracking. Enable \`Identify visitors by IP\`, disable \`Anonymize IP\`.
> Open incognito browser, go to site, observe that anonymous user is created by your ip.
> do something to post your email (e.g. post form). Close.
> Open new incognito browser, go to site, observe that a new anonymous user is created instead of adopting previous.
> 
> \<!--
> If you have any deprecations, list them here along with the new alternative.
> If you have any backwards compatibility breaks, list them here.
> \--\>

to solve this (I think)
