# Javascript landing page contact tagging inconsistent behaviour

**URL:** https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480
**Category:** General Discussion
**Created:** [September 22, 2022, 7:49am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480 "2022-09-22T07:49:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![deanw](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/deanw/32/677_2.png) [@deanw](https://forum.mautic.org/u/deanw)
#### Post date: [September 22, 2022, 7:49am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/1 "2022-09-22T07:49:40Z")

</div>

I’m using the javascript tag method to update contacts with a tag as provided here [Instant Double Opt-in without cronjobs (3 examples) – Joey Keller](https://joeykeller.com/instant-double-opt-in-without-cronjobs-3-examples/).

```
<script>
	function getUrlParameter(name) {
		name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
		var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
		var results = regex.exec(location.search);
		return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
	};
	
	(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://yourmautic.com/mtc.js','mt');

	var email = getUrlParameter('email');

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

```

However sometimes the contact is not updated in Mautic after the contact visits the landing page. This seems to happen at random. It will work one day and the next it will not. It will tag some contacts but others it will not.

I am using a browser with clean cache and emails never used before on the Mautic instance. I’m also making sure the Mautic admin uses a different browser and is not open when testing.

Has anyone else seen similar behaviour when using this javascript on external landing pages?

---

<div class="post-metadata">

### Author: ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)
#### Post date: [September 22, 2022, 8:44am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/2 "2022-09-22T08:44:24Z")

</div>

Hi,  
As personally mentioned 🙂 I would like to chime it:  
External landing page: is that on another domain?  
Joey

---

<div class="post-metadata">

### Author: ![deanw](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/deanw/32/677_2.png) [@deanw](https://forum.mautic.org/u/deanw)
#### Post date: [September 22, 2022, 9:25am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/3 "2022-09-22T09:25:20Z")

</div>

Hi Joey,  
That’s a a very quick reply and from the author himself! The tracking/tagging script is included in the external [https://domain.com](https://domain.com) landing-page. Mautic is on a subdomain [https://mautic.domain.com](https://mautic.domain.com) with the domain CORS whitelisted in the Mautic config.

I’m using the javascript on two domains landing pages each with their own Mautic. Both are showing this behaviour.

The contacts are sent to the subscription confirmation landing page via the double opt-in email. This is passing the contact email and name.

[https://domain.com/subscription-thank-you/?email={contactfield=email}&name={contactfield=firstname}](https://domain.com/subscription-thank-you/?email=%7Bcontactfield=email%7D&name=%7Bcontactfield=firstname%7D)

Dean

---

<div class="post-metadata">

### Author: ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)
#### Post date: [September 22, 2022, 2:13pm UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/4 "2022-09-22T14:13:27Z")

</div>

Very weird, when it ‘sometimes’ happens. You will need to find some kind of rule, so I can reproduce it.  
If you want you can send me the page in private message, and I take a look!

---

<div class="post-metadata">

### Author: ![deanw](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/deanw/32/677_2.png) [@deanw](https://forum.mautic.org/u/deanw)
#### Post date: [September 27, 2022, 3:03am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/5 "2022-09-27T03:03:40Z")

</div>

Hi Joey,  
It was a problem with other javascript on the site interferring with the Mautic tracking javascript. Now the tracking and tagging is working perfectly using the script on the landing page.

---

<div class="post-metadata">

### Author: ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)
#### Post date: [September 30, 2022, 6:04pm UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/6 "2022-09-30T18:04:33Z")

</div>

Great thx for feedback. Happy that you cracked it.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/43c63600fe51440378769136903f1fa2a9a34102.png) [@system](https://forum.mautic.org/u/system)
#### Post date: [October 28, 2022, 12:39am UTC](https://forum.mautic.org/t/javascript-landing-page-contact-tagging-inconsistent-behaviour/25480/7 "2022-10-28T00:39:38Z")

</div>

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.
