Using a Unique ID for Tracking Code

Hi all,

I could use some help with generating a Unique ID variable from each Form Submission and referencing that ID in a tracking code that is placed in the Header of my thank you page that each form submission is sent to. I have a basic understanding of JS and Velo.

Tracking code:
External Media

The “SF314” string is meant to be a unique variable.

I know there is a variable called “_ID” or something similar in the Form database which is assigned to each Form Submission. I also know that there is probably a way to generate that variable on the thank you page by using Wix Database functions on the Form Submission page and then pulling that information to the Thank You page?

My two questions would be:

  1. How would I store and generate that unique variable on the Thank You page (I really have tried using the Wix Database guide but I’m not quite grasping it).

  2. How do I reference that unique ID in the HTML tracking code? Is there a way to just reference the Database “_ID” variable attached to each form submission in the tracking code without generating it on the Thank You page?

Thank you in advance!

Hi,
Each collection document has an auto-generated ID (field key: _id ).
I don’t know which method you chose to use in order to submit the form, so I’ll so you how to do it with wixData.

//...import wixData, wixLocation, have $w.onready(), have an onClick event handler to submit, on submit collect the input values into an object then:
wixData.insert("FormCollectionName", object)
.then(obj => {
wixLocation.to("/thank-you?id=" + obj._id;
})
//...

In the thank you page script add at the beginning:

<script>
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get("id");
</script>
//and use the id in the tracking code

Thank you for the reply, and I pretty much understand what you’ve posted, but will that “id” in the Thank You page script return a unique variable that the HTML-based Tracking Code (which I am adding as a Custom Code in the Wix Dashboard) be able to pull each time?

@joshdavidking the ID will be a universally unique identifier.