# Tracking contact by collecting email from URL is not working

**URL:** <https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262>\
**Category:** Product Support\
**Created:** [December 1, 2022, 12:11pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262 "2022-12-01T12:11:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/saikat/32/6368_2.png) [@saikat](https://forum.mautic.org/u/saikat)\
**Post date:** [December 1, 2022, 12:11pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/1 "2022-12-01T12:11:57Z")

</div>

**Your software**  
My Mautic version is: v.4.44

**Your problem**  
My URL will look like [https://xyz.com/page.html?email=abc@abc.com](https://xyz.com/page.html?email=abc@abc.com)

Using the following JS to fetch the email from URL and push to Mautic tracking.

```auto
<script>
  
 var url_string = window.location.href
 var url = new URL(url_string);
 var customer_email = url.searchParams.get("email");
  

 
    (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','https://xyz.com/mtk/mtc.js','mt');

    if(customer_email != ''){
      alert(customer_email);
		mt('send', 'pageview', {email: customer_email});
	} else {
		mt('send', 'pageview');
	}
  
  
</script>

```

I have verified that the variable _customer\_email_ is correctly getting the email. But, Mautic is not identifying the contact.

Am I doing anything wrong?

---

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/leoschuler/32/4798_2.png) [@leoschuler](https://forum.mautic.org/u/leoschuler)\
**Post date:** [December 1, 2022, 12:45pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/2 "2022-12-01T12:45:11Z")

</div>

check if the email field is set as “Publicly updatable” under settings → Custom Fields → Email

only the fields that are set as publicly updatable can be changed by the tracking code.

but keep in mind that this is a trade: users can manipulate this code to send the data they want, for example, if the user manually change the value of the customer\_email on your url, you will include the value they input, not necessarily their actual email.

also, keep in mind that email is a personal data, and adding personal data to the url can be consider a data breach since that information is openly transmitted throughout the internet and logged into browsers and routers - if you need to transmit that value between 2 pages of your website, a more secure way would be to use session cookies.

---

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/leoschuler/32/4798_2.png) [@leoschuler](https://forum.mautic.org/u/leoschuler)\
**Post date:** [December 1, 2022, 1:00pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/3 "2022-12-01T13:00:10Z")

</div>

oh, another thing you should be checking is that mautic will not track user navigation for people logged in mautic. in order to test the tracking you need to open a different browser or open the browser in incognito mode.

---

<div class="post-metadata">

**Author:** ![saikat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/saikat/32/6368_2.png) [@saikat](https://forum.mautic.org/u/saikat)\
**Post date:** [December 1, 2022, 1:53pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/4 "2022-12-01T13:53:40Z")

</div>

Yes, it’s working now. Thank you so much.

How can I use cookies to achieve this?

---

<div class="post-metadata">

**Author:** ![leoschuler](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/leoschuler/32/4798_2.png) [@leoschuler](https://forum.mautic.org/u/leoschuler)\
**Post date:** [December 1, 2022, 2:20pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/5 "2022-12-01T14:20:30Z")

</div>

better and simpler than cookies is to use the local or session storage object, it would not work on very old browsers: ["sessionStorage" | Can I use... Support tables for HTML5, CSS3, etc](https://caniuse.com/?search=sessionStorage)

assuming you have pages on the same domain,  
on the page where you collected the e-mail, lets say to an input field called email:

```auto
<script>
//collect the e-mail from a field:
var userEmail = document.getElementById("emailField").value;

// Save data to sessionStorage
sessionStorage.setItem("email", userEmail );
</script>

```

Now, on the page where do you want to send the data to mautic:

```auto
<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','https://xyz.com/mtk/mtc.js','mt');

// Get saved data from sessionStorage
var customer_email = sessionStorage.getItem("email");

    if(customer_email != ''){
      alert(customer_email);
		mt('send', 'pageview', {email: customer_email});
	} else {
		mt('send', 'pageview');
	}
</script>

```

---

<div class="post-metadata">

**Author:** ![saikat](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/saikat/32/6368_2.png) [@saikat](https://forum.mautic.org/u/saikat)\
**Post date:** [December 1, 2022, 5:34pm UTC](https://forum.mautic.org/t/tracking-contact-by-collecting-email-from-url-is-not-working/26262/6 "2022-12-01T17:34:30Z")

</div>

Perfect. I will try this.  
Thank you for this idea.
