Single Page Tracking

Automatically append the AnyTrack click ID to your page URL to track form submissions when hidden fields are not supported. Includes setup instructions, prerequisites, and best practices.

Overview

Some form builders and embedded forms do not support injecting the AnyTrack click ID into hidden fields via the standard AnyTrack tracking tag.

To solve this, AnyTrack provides a custom JavaScript snippet that automatically appends the AnyTrack click ID to the current page URL when the page loads.

This allows third-party forms to capture the click ID directly from the URL parameters.


Prerequisites

Before you begin

  • You can edit your website or funnel
  • You have access to your AnyTrack account
  • Form builder that supports URL parameter reading

⚠️ Important: Recommended Form Tracking Method (When Supported)

Before using this URL-based approach, we strongly recommend using standard AnyTrack form tracking whenever your form builder supports it.

Standard setup:

  1. Add a hidden field to your form

  2. Set its default value to:

    --CLICK-ID--
  3. The AnyTrack tracking tag automatically substitutes this token with the real click ID at runtime

  4. The click ID is:

    • Sent to your CRM or backend with the form submission
    • Returned to AnyTrack for server-side conversion tracking and attribution

This method is more robust and should be preferred whenever hidden fields and default values are supported.

πŸ‘‰ Use the URL-based solution below only if hidden field injection is not possible.


When to Use the URL-Based Click ID Appending

Use this solution if:

  • Your form is hosted on your website
  • The form cannot read values from the AnyTrack tracking tag
  • The form can capture values from URL parameters

Typical examples include external form tools, embedded widgets, or legacy form builders with limited customization options.


How It Works

  1. The script waits until the AnyTrack library is fully loaded
  2. It retrieves the AnyTrack click ID (atclid)
  3. It appends the click ID to the current page URL as a query parameter
  4. The page URL is updated using history.replaceState (no page reload)

The form can then read the click ID directly from the URL.


Default URL Parameter

By default, the click ID is appended using the following parameter:

_atid

Example:

https://example.com/landing-page?_atid=ANYTRACK_CLICK_ID

Installation Instructions

  1. Copy the script below
  2. Paste it into the <head> section of your website
  3. Place it alongside your regular AnyTrack tracking tag

Custom JavaScript Tag

<script>
!function(){let t,e=30;const n=setInterval((()=>{try{(function(){const{location:e,history:n,AnyTrack:r}=window;if("function"!=typeof r)return!1;if(r.q)return!1;const a=r("atclid");if(!a)return!1;const c="_atid";let l=e.href;e.hash&&(l=l.replace(/#.*$/,""));const o=`([?&])${c}=([^&]*)(&|$)`,s=l.match(new RegExp(o));if(s){if(t===s[2])return!0;l=l.replace(s[0],s[3]?s[1]:"")}return l+=`${l.includes("?")?"&":"?"}${c}=${a}`,t=a,e.hash&&(l+=e.hash),n.replaceState(n.state||null,"",l),!0}()||e--<=0)&&clearInterval(n)}catch(t){clearInterval(n),console.log(`Error replacing state: ${t.message} \n ${t.stack}`,t)}}),200)}();
</script>

Customizing the URL Parameter

If your form expects a different parameter name, you can change it in the script.

Locate this line:

const c = "_atid";

Replace _atid with the parameter name required by your form provider.

Example:

const c = "click_id";

Notes & Best Practices

  • This script does not reload the page
  • The URL is updated safely using browser history APIs
  • Compatible with hash-based URLs
  • Designed for privacy-first, first-party tracking setups
  • Use only when hidden field injection is not supported

Result

Your form will be able to capture the AnyTrack click ID from the page URL and pass it to your backend or CRM, enabling accurate server-side conversion tracking and attribution.