# Tracking Code or Rest API: How to create new users in mautic? How to get mautic contact id from tracking?

**URL:** https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411
**Category:** Product Support
**Created:** [May 11, 2021, 4:38am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411 "2021-05-11T04:38:48Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![iparker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/iparker/32/1936_2.png) [@iparker](https://forum.mautic.org/u/iparker)
#### Post date: [May 11, 2021, 4:38am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/1 "2021-05-11T04:38:49Z")

</div>

Hello,

I’m new using mautic and have a question about how to generate new users in mautic.

My use case is a simple registration form on a website. And important: This is not a form from mautic!

When I include the tracking code mautic is the first instance that knows about the user (as visitor). So the user clicks on the page (what is already tracked by mautic), hits the registration form and registers on my site/in my backend.

After this I pass the user data like name and email to the mautic tracking code as custom parameters. This turns the visitor to a know contact in mautic.

I hope I get and explained the mautic-flow right so far.

I ask myself if its necessary to do also any rest call after registration, maybe kind of registration-event-listener which creates a contact in mautic via Rest API. But I think this is not needed because mautic already has created this contact.

One of my requirements is that I want to save the mautic contact id also in my data (for knowing if the user is already connected with mautic and to identify the contact in mautic).

So what is a good way to handle this if the contact was created with tracking code? In case of Rest-Call it would be clear - I think the rest response should contain the mautic contact id. But how can I get the contact id if there is rest call?

Hope you can understand my explanation and help me with this issue!

Best regards,

Timo

---

<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: [May 11, 2021, 6:00am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/2 "2021-05-11T06:00:05Z")

</div>

Hi, it is well documented here:

> **[Contact tracking](https://docs.mautic.org/en/contacts/manage-contacts/contact-monitoring)**
>
> . The act of monitoring the traffic and activity of contacts can sometimes be somewhat technical and frustrating to understand. Mautic makes this monitoring simple and easy to configure.Website Monitoring. Monitoring all traffic on a website can be...

There are multiple ways how the tracking data can be added.  
Also check this:

> **[Tracking Visitor Data by Smart URL](https://www.mautic.org/blog/developer/tracking-visitor-data-by-smart-url)**
>
> Have you ever wondered if you could track more than just visits via the Mautic tracking script?

If you make rest calls, you can always use the email as unique identifier for getting the contact ID. See docs.

---

<div class="post-metadata">

### Author: ![iparker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/iparker/32/1936_2.png) [@iparker](https://forum.mautic.org/u/iparker)
#### Post date: [May 11, 2021, 7:12am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/3 "2021-05-11T07:12:31Z")

</div>

Hello,

thanks for your reply!

I have to re-ask to make it clear for me:

1.) When I use the tracking script with custom parameters for the user it is not necessary to create a contact in mautic via rest api because the contact is created by the tracking script. Right?

2.) To get the mautic contact I can make a rest call on the server side so I can get and save the mautic contact id in my data/backend. Right?  
Or is there another way, maybe get the contact with mautic js api in client?

Thanks for some help with this!

Best regards,

Timo

---

<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: [May 11, 2021, 8:53am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/4 "2021-05-11T08:53:57Z")

</div>

> [@iparker](#):
>
> 1.) When I use the tracking script with custom parameters for the user it is not necessary to create a contact in mautic via rest api because the contact is created by the tracking script. Right?
> 
> 2.) To get the mautic contact I can make a rest call on the server side so I can get and save the mautic contact id in my data/backend. Right?  
> Or is there another way, maybe get the contact with mautic js api in client?

Hi,

1. Correct, the js will check the cookie. If it’s available, then append info, if not, then create a new contact.

2. Correct. Not sure exactly in what environment you want to do it, but you can do it.

---

<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: [May 11, 2021, 8:54am UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/5 "2021-05-11T08:54:54Z")

</div>

You should check this Forum thread to be aware of the limitations:

> [@Tracking Code & Shopify Not Matching up to Contacts](https://forum.mautic.org/t/tracking-code-shopify-not-matching-up-to-contacts/16465):
>
> Your software My Mautic version is: 2.16.3 My PHP version is: 7.2 Your problem My problem is: We have installed the tracking code on Shopify and enabled on Mautic side: Identify visitor by tracking url Identify visitor by device fingerprint Identify visitors by IP The problem is that we are able to track all visitors however it is not connecting them to the contacts. I signed in as a user, see that I am signed in, however I do not see any Events under my contact. Any pointers on how t…

---

<div class="post-metadata">

### Author: ![iparker](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/iparker/32/1936_2.png) [@iparker](https://forum.mautic.org/u/iparker)
#### Post date: [May 19, 2021, 12:33pm UTC](https://forum.mautic.org/t/tracking-code-or-rest-api-how-to-create-new-users-in-mautic-how-to-get-mautic-contact-id-from-tracking/19411/6 "2021-05-19T12:33:58Z")

</div>

Thanks for your reply and sorry for my late reponse.

Unfortunately I have to reask cause I’m very unsure with this:

Would you recommend to create a new contact with custom parameters in tracking script (like: mt(‘send’, ‘pageview’, {email: ‘my@email.com’, firstname: ‘John’})) or is it better to make a rest call to create a new contact?

I’m really unsure what data I should send in custom parameters in tracking script. Nothing? Just a uuid or the email? Or even all relevant data mautic has to know about the contact?

What are best practices for this use case?

Hope you can help me with this!

Best regards,

Timo
