Instrumentation

CampaignCollector.js

GZip size

CampaignCollector is a small utility library that allows you to easily collect campaign parameters (utm_ +) from a URL and store/persist them in browser storage. This is useful for integrating campaign data with lead generation forms and CRMs.

  • Natively supports all 9 standard campaign parameters (e.g., utm_*).
  • Supports storage of 17 custom parameters with a separate defined prefix (e.g., lvl_).
  • Ability to define field mappings for each parameter to attach data to form submissions.
  • Define 1st party cookies and global variables to capture and map along side your in-url campaign parameters.

Installation

Google Tag Manager (Easiest)

For Google Tag Manager users - this is the preferred and easiest deployment method.

Install the Campaign Collector tag template from the community gallery. You can view the tag template repository here.

This method is also suggested for data-privacy compliance. This library is configured to react to changes in Google Consent Mode and will change the data that is captured and/or stored based on the consent state of the user.

Vanilla Javascript Loader

In the event you need to have more control over the logic of when the library is loaded - you can use the following async loader to mount an instance.

This most often will apply to users using a different TMS like Adobe Launch, or those who are not using a TMS at all.

1(function(l,o,a,d,e,r){
2e=o.createElement(a);e.onload=d;e.defer=1;
3e.src="https://cdn.jsdelivr.net/gh/levelinteractive/[email protected]/dist/core.min.js";
4r=o.getElementsByTagName(a)[0];r.parentNode.insertBefore(e,r);
5})(window, document, 'script', function() {
6 
7 // Initialize an instance
8 window._CampaignData = new CampaignCollector();
9 
10});

NPM

The library has not been released as an NPM package (yet). It is something on our radar. Due to the primary deployment method of GTM, NPM isn't as necessary.

Supported Campaign Parameters

Standard Parameters

Google has defined a set of standard UTM parameters that are widely supported across advertising/martech platforms. These parameters are natively supported by the library.

  • utm_source
  • utm_medium
  • utm_campaign
  • utm_term
  • utm_content
  • utm_id
  • utm_marketing_tactic
  • utm_creative_format
  • utm_source_platform

Custom Parameters

In addition to the standard parameters - this library offers flexibility for a set list of custom parameters. By default, the library will look for any parameter that starts with specific namespace (lvl by default). The namespace/prefix can be customized by setting the namespace config option to a different value. These parameters align closely with major advertising platform URL macros (e.g., Google Ads "ValueTrack" and similar).

  • lvl_platform
  • lvl_source
  • lvl_campaign_name
  • lvl_campaign
  • lvl_group
  • lvl_ad
  • lvl_creative
  • lvl_feed
  • lvl_product
  • lvl_extension
  • lvl_geo_int
  • lvl_geo_phy
  • lvl_device
  • lvl_matchtype
  • lvl_placement
  • lvl_network
  • lvl_target

The custom parameters are not extendable at this time. We may offer that capability in future versions, however there are no current plans to do so.

Session Logic

The library uses a timeout-based session approach to store the "last" touch campaign data. This is similar to how Google Analytics functions (but not exact).

  • An active session with explicit campaign data cannot be overwritten by referrer parsing.
  • On a users first visit, the first and last touch data will be the same.
  • Sessions expire after 30 minutes of inactivity (unless customized via sessionTimeout in the config). "Inactivity" is defined as no page views, or generic click events on the page.
  • First touch data will be misleading for browsers that cap cookie expiration at 7 days (e.g. Safari/Firefox etc...). This can be mitigated (to an extent) by rewriting the _cc_first cookie via a 1st party service - this requires infrastructure not provided by this library.

Scenario Example

  1. A "first time visitor" enters the site on a page with ?utm_source=google&utm_medium=cpc&utm_campaign=helloworld in the URL.
  2. A new session is started, and the first and last touch data is set to the above parameters.
  3. (10 Minutes Pass) The user opens a new tab in Google/Bing and searches your brand, then clicks on an organic result.
  4. A new session is NOT started -- because the active session has explicit campaign data. The existing session is extended an additional 30 minutes.
  5. (> 30 Minutes Pass) The user sees an organic social media post and clicks a link to your site.
  6. A new session IS started, and the last touch data is set to the explicit campaign data in the URL (if present) -OR- the referrer is parsed to implicitly set a source/medium.
  7. In the event that direct URL attribution via parameters and referrer parsing fails, the session (e.g. last touch utm.source and utm.medium is set to (direct) and (none)).

© 2026 Level Agency.