Skip to main content
Tracking Events When Using OAuth

Learn how to track attribution events when using OAuth in your funnel.

Updated over a week ago

When a user interacts with OAuth on your site, you’ll need to send a custom event to ensure Cometly can properly track the attribution journey. Typically, our script automatically captures important form fields like email, first name, last name, and phone number. However, with OAuth, it’s important to send a manual event to capture these details, including the critical comet_token, which assists in tracking the event back to the original journey.

What is the comet_token?

The comet_token is a unique identifier that links a user's actions to their attribution journey in Cometly. This token must be captured at the time the user clicks the OAuth, and you can retrieve it using the cometToken() function available via the Cometly tracking code installed on your site. This function returns the comet_token as a string, which you'll include in your event payload.

To verify the comet_token is being generated and sent, you can inspect your page using your browser’s developer tools:

  1. Right-click on the page and select Inspect.

  2. Go to the Network tab.

  3. In the search bar, type comet.

  4. Look for Fetch/XHR events, then click on the init event in the list.

  5. Navigate to the Payload section, and you will see the comet_token included in the data.

Retrieving the comet_token Programmatically

You can also retrieve the comet_token programmatically from your site’s tracking code. Here’s an example of how to do it: (this is an example code snippet):

// Example code to retrieve the comet_token
var cometToken = cometToken(); // This will return the comet_token as a string
console.log(cometToken); // You can then use this token in your event payload

Minimum Required Payload

You can send any event that makes sense for your workflow, but the minimum required payload must include the event_name, email, and comet_token.

Here’s an example of the minimum payload to accurately track:

{
"event_name": "lead_generated",
"email": "developers@cometly.com",
"comet_token": "ddffd8d8338383883838484843838388d8df8f"
}

Recommended Payload

For better attribution accuracy, we recommend including additional details such as first_name and last_name (or full_name).

Here’s an example of a more detailed event payload to accurately track:

{
"event_name": "lead_generated",
"email": "developers@cometly.com",
"comet_token": "ddffd8d8338383883838484843838388d8df8f",
"first_name": "John",
"last_name": "Smith"
}

Alternatively, you can provide the full name in a single field:

{
"event_name": "lead_generated",
"email": "developers@cometly.com",
"comet_token": "ddffd8d8338383883838484843838388d8df8f",
"full_name": "John Smith"
}

For more detailed information on event fields and advanced options, check out our developer documentation.

Did this answer your question?