Form Activity Tracking

Form Activity Tracking

Form Activity Tracking

This documentation describes a JavaScript script designed to listen to form events. The script captures data sent through form events and logs it for further processing or analysis.

This documentation describes a JavaScript script designed to listen to form events. The script captures data sent through form events and logs it for further processing or analysis.

Script Details

html

<script>
	window.addEventListener("message", (event) => {
		if (event.origin === "https://workhack.forms.workhack.ai") {
			const data = event.data;
			console.log(`Received data from ${data.formId} of type ${data.type}`);
		}
	});
<

Event Data Structure

The event data received by the listener is an object with the following structure:

  • formId: A string indicating the form this event originated from.

  • type: A string indicating the type of event. Possible values include "start", "next_page", "end", and "cta".

  • data: An object containing key-value pairs. The keys represent question names, and the values are the corresponding answers. For events of type "cta", the key will be the label of the CTA (Call To Action) button, and the value will be the associated link URL. It includes all the data collected so far.

Example Data Received

In this example, the event type is "next_page," and the data object contains answers to two questions.

json

{ "formId": "6584382cf9ac948b56336f0f", 
  "type": "next_page", 
  "data": { "question1": "answer1", "question2": "answer2" } }

Script Details

html

<script>
	window.addEventListener("message", (event) => {
		if (event.origin === "https://workhack.forms.workhack.ai") {
			const data = event.data;
			console.log(`Received data from ${data.formId} of type ${data.type}`);
		}
	});
<

Event Data Structure

The event data received by the listener is an object with the following structure:

  • formId: A string indicating the form this event originated from.

  • type: A string indicating the type of event. Possible values include "start", "next_page", "end", and "cta".

  • data: An object containing key-value pairs. The keys represent question names, and the values are the corresponding answers. For events of type "cta", the key will be the label of the CTA (Call To Action) button, and the value will be the associated link URL. It includes all the data collected so far.

Example Data Received

In this example, the event type is "next_page," and the data object contains answers to two questions.

json

{ "formId": "6584382cf9ac948b56336f0f", 
  "type": "next_page", 
  "data": { "question1": "answer1", "question2": "answer2" } }