LogoLogo
Back to studio
  • 🧠Core Concepts
    • Introduction to Formsort
    • Formsort quickstart guides
      • Add content and collect answers
      • Capture demographic data
      • Add informational content
      • Template your variables
      • Add conditional logic
      • Using conditional logic with Calculated and API variables
      • Add a scheduling option
      • End the flow
      • Review your variable schema
      • Set up integrations
    • How data works in Formsort
      • Responder UUIDs
    • Understanding flows
    • Versioning in Formsort (Deploying)
      • Variant revisions
      • Managing revisions
  • ✨Creating Flows
    • Building a new flow
      • Groups
      • Steps
      • Copy-pasting form content
  • Adding questions and content
    • Questions
      • Select
      • Text
      • Address
      • Comparison
      • Confirmation
      • Date
      • Date & time
      • Email address
      • File upload
      • Grid choice
      • Iframe
      • Image upload
      • Number
      • Payment
      • Phone number
      • Postal code
      • Question group
      • Region
      • Signature
      • SSN
      • Yes/No
    • Content
      • Statement
      • Image
      • Next button
      • Video
      • Divider
      • Map
  • Controlling the flow with conditions and logic
    • Advanced logic
  • Variable templating
  • Redirects and endings
  • Field validation
  • Flow and variant management
  • Content library
  • 🧬JSON Form Definition
  • JSON schemas
  • Validating flow schemas
  • Events subscriptions
  • Flow content data format
  • 🎨Styling
    • Customizing appearance
      • Content area & form layout
      • Buttons
      • Typography
      • UI states
      • Color and dimension variables
      • Question containers
      • Inputs and dropdowns
      • Checkmarks
      • Tables
      • Sliders
      • Divider lines
      • Progress bar
      • Comparison cards
      • Animations and transitions
  • CSS & Advanced Styling
    • Custom CSS overrides
    • Step styling
    • CSS reference
  • 🔁Form Behavior Settings
    • Variant settings
      • Form behavior for returning users
      • Group ranking API
    • Navigation sidebar
  • ⚙️Response Data Collection & Management
    • Schema (variables)
      • Variables from questions
      • Externally provided variables
      • Calculated variables
      • API lookups
      • System Library variables
      • Orphaned variables
  • Saving & retrieving responses
  • Importing Data
    • URL parameters
    • POST body
    • Embed query parameters
  • 📊Analytics and Attribution
    • Built-in analytics
    • Split testing
  • 🚀Publishing and Deployment
    • Live preview overview
    • Environments
      • Loading different environments
    • Embedding
      • Web-embed API
        • React-embed
      • Adding authentication
      • Embedding forms in iOS and Android
      • Setting up a dev environment
    • Pre-deployment checklist
  • 📁Workspace Management
    • Accounts
      • Roles and permissions
    • Custom domains
    • Workspace domain detection
  • 🛠️Formsort Admin API
    • Admin API
  • 🔌Integrations
    • Form answers and events
      • Analytics events
      • Signed requests
      • Event payload shape
      • Submission frequencies
      • Runtime error reporting
    • Integration reference
      • Amplitude
        • Amplitude cross domain tracking
      • BigQuery
      • FullStory
      • Google Analytics
        • Updating from Universal Analytics to GA4
      • Google Cloud Storage
      • Google Sheets
      • Google Tag Manager (GTM)
        • JavaScript triggered by flow events
      • Hubspot
      • Jornaya
      • Optimizely
      • PostgreSQL
      • Redshift
      • Rudderstack
      • S3
      • Salesforce
      • Segment
        • Segment Setup
        • Segment cross domain tracking
      • Stripe
      • TrustedForm
      • Webhooks
        • Zapier
Powered by GitBook
On this page
  • Custom events
  • Example function

Was this helpful?

  1. Integrations
  2. Integration reference
  3. Google Tag Manager (GTM)

JavaScript triggered by flow events

Run JavaScript via Google Tag Manager

PreviousGoogle Tag Manager (GTM)NextHubspot

Last updated 11 months ago

Was this helpful?

Formsort integrates directly with a number of 3rd party tools. If the tool you need does not have a prebuilt integration, Google Tag Manager can be used to run JavaScript to extend Formsort's capabilities

Running JavaScript via Google Tag Manager should only be done as a last resort. Formsort cannot provide support for this functionality or guarantee that it will not negatively impact your flows.

Custom events

Formsort dispatches custom events via . These events can be listened to and used to trigger JavaScript via Google Tag Manager.

The following is a list of events with payload definitions:

  • FlowLoaded

{
	flowLabel: string;
	variantLabel: string;
	deploymentUuid: string;
	experimentId?: string;
	formsortEnv: string; // production, staging etc.
}
  • StepLoaded

{
	stepIndex: number;
	stepId: string | number; // loaded step id, falls back to step index if step id is not given
	// and variant details defined in FlowLoaded
}
  • StepCompleted

{
  stepIndex: number,
  stepId: string | number;
  msSpentOnStep: number; // time in milliseconds user spent on this step
  // and variant details defined in FlowLoaded
}
  • FlowFinalized

{
  stepIndex: string; // final step index
  stepId: string | number; // final step id falling back to index number
  redirectUrl?: string; // redirect url of final step (optional)
  // and variant details defined in FlowLoaded
}

Example function

The following JavaScript for a mock analytics service can be triggered in Google Tag Manager based on a single step of a multi-step flow via the StepLoaded event.

window.addEventListener('StepLoaded', (event) => {
	const payload = event.details;
	
	if (payload.stepId === 'watch_this_step') {
		const thirdPartyScript = document.createElement('script');
		thidrPartyScript.src = '...';
		document.head.appendChild(thidrPartyScript);
		
		fetch('my-api-url.com/record-start-event', {
			method: 'POST',
			body: JSON.stringify({ flowLabel: payload.flowLabel, timeStamp: +Date.now() }),
			headers: {
				'content-type': 'application/json',
			},
		})
	}
});

window.addEventListener('StepCompleted', (event) => {
	const payload = event.details;
	
	if (payload.stepId === 'watch_this_step') {
		window.thirdPartyService.stopRecording();
		
		fetch('my-api-url.com/record-end-event', {
			method: 'POST',
			body: JSON.stringify({ flowLabel: payload.flowLabel, timeStamp: +Date.now() }),
			headers: {
				'content-type': 'application/json',
			},
		})
	}
});

🔌
custom event api