Website tracking & GTM

Put what contacts do on your website on their CRM timeline: products viewed, carts, checkouts, purchases and your own events. From there they work like any other event: in segments, as automation triggers (an abandoned-cart flow, say) and in webhooks.

It installs through Google Tag Manager (a tag template) or a plain snippet, reads the GA4 e-commerce events your data layer probably already has, and waits for cookie consent before it stores anything.

How it works

  1. You add a website under Settings → Website tracking and get a public site key (cfs_…).
  2. The tracker (/public/t.js) runs on your site. Once the visitor accepts analytics cookies it gives them a first-party visitor id and sends events in small batches.
  3. Events from an anonymous visitor are kept, not put on any timeline.
  4. When the CRM learns who the visitor is, everything they did before is replayed onto that contact's timeline with its original time. That happens when they log in or fill in a form and your site identifies them, when they arrive from a link in one of your CRM emails, when the purchase event carries their email, or when they buy and the order reaches the CRM (see Identifying visitors). A new contact is created only from an email, and only if you allow it.
  5. From then on their events go straight to the timeline.

Events are processed in the background, usually within a few seconds, so a busy shop never waits on the CRM.

If the CRM can't be reached for a moment, or asks the tracker to slow down, the tracker keeps the events and sends them again, also from the visitor's next page. Each event has its own id, so one sent twice is stored once. The browser keeps them for up to three days and at most 200 events, and only after the visitor has allowed statistics cookies. One page sends at most 30 requests a minute, so a site that pushes events in a loop can't flood the CRM: the rest wait for the next minute, up to the same 200 events. There is nothing to set up.

Install with Google Tag Manager

  1. In Settings → Website tracking, add your website with the domains it runs on, and download the tag template.
  2. In GTM: Templates → Tag templates → New → ⋮ → Import, pick code-fab-crm.tpl, save.
  3. Tags → New → Code F CRM, action Load the tracker, paste the site key. Fire it on Consent Initialization – All Pages (or Initialization – All Pages).
  4. Optional: a second Code F CRM tag with action Identify the visitor on your login or order-confirmation step, with the email from a data layer variable.
  5. Publish.

With Require consent ticked (the default) the tag waits for the visitor's answer, see Consent.

On a Viskan shop, also follow Set up on Viskan: where the container id goes on Streamline 4 and Streamline 3, and the security setting Streamline 4 needs.

Install without GTM

Put this in the <head> of every page:

HTML
<script>
window.cfcrm=window.cfcrm||function(){(cfcrm.q=cfcrm.q||[]).push(arguments)};
cfcrm('init', 'cfs_your_site_key', { consent: 'required' });
</script>
<script async src="https://crm.codefab.dev/public/t.js"></script>

When the visitor answers your consent banner:

Node.js
cfcrm('consent', true); // statistics and marketing
cfcrm('consent', true, { marketing: false }); // statistics only: nobody is named
cfcrm('consent', false); // refused, or withdrawn later

If your banner already reports to Google Consent Mode, or is Cookiebot or Cookie Information, the tracker picks the answer up by itself (see Consent). Use consent: 'granted' only if you have another lawful basis and have decided no banner is needed.

If you use GTM but can't import a tag template, add the snippet above as a Custom HTML tag instead and fire it on Consent Initialization – All Pages. The snippet has to run on every page, before the visitor's consent answer; a page builder's HTML block placed on some pages doesn't do that.

  • Nothing before the answer. Until the visitor has answered your cookie banner, nothing is sent and no cookie is set. Events from before the answer wait in the browser (up to 50) and are sent only if the visitor allows statistics cookies; if they refuse, the events are dropped.
  • Statistics lets the tracker set its visitor cookie and send events.
  • Marketing is needed to tie those events to a person: identifying the visitor, the cart reminders and everything on a contact's timeline. With statistics only, events are kept as anonymous raw hits.
  • Withdrawn consent stops tracking and removes the visitor cookie.

Where the answer comes from:

SourceStatisticsMarketing
Google Consent Modeanalytics_storagead_user_data (else ad_storage)
CookiebotCookiebot.consent.statisticsCookiebot.consent.marketing
Cookie Informationcookie_cat_statisticcookie_cat_marketing
Your own bannercfcrm('consent', …)cfcrm('consent', true, { marketing }) or cfcrm('marketing', true | false)

In the GTM tag, Where the consent answer comes from picks Consent Mode (the default) or the banner. Consent Mode treats a type it was never told about as granted, so it needs a default of denied before the tag fires. If your banner does not set one, pick the banner.

Commands

CommandWhat it does
cfcrm('init', key, options)Starts the tracker. Options below.
cfcrm('consent', true | false, { marketing })Grants or withdraws consent. marketing defaults to the same answer.
cfcrm('marketing', true | false)Changes only the marketing answer.
cfcrm('identify', { email, externalId, firstName, lastName })Says who the visitor is. email or externalId is required.
cfcrm('track', name, props)Sends your own event. It arrives as web.<name>.
cfcrm('page')Records a page view by hand (single-page apps are followed automatically).

init options:

OptionDefault
consent'required''required' waits for consent; 'granted' starts straight away.
dataLayertrueRead GA4 events and consent from the data layer.
dataLayerName'dataLayer'If your data layer has another name.
pageViewstrueSend page views, including route changes in single-page apps.

GA4 e-commerce events

If your site pushes GA4 recommended events to the data layer, nothing more is needed. They are forwarded as they happen:

Node.js
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: 'SEK', value: 499,
items: [{ item_id: 'SKU-1', item_name: 'Blue hoodie', price: 499, quantity: 1 }]
}
});
GA4 eventCRM event
page_viewweb.page_viewed
view_itemweb.product_viewed
view_item_listweb.list_viewed
select_itemweb.product_selected
add_to_cart / remove_from_cartweb.added_to_cart / web.removed_from_cart
view_cartweb.cart_viewed
cart_update (the full cart after a change)web.cart_updated
begin_checkoutweb.checkout_started
add_shipping_info / add_payment_infoweb.shipping_added / web.payment_added
purchase / refundweb.purchased / web.refunded
sign_up / loginweb.signed_up / web.logged_in
generate_leadweb.lead_submitted
searchweb.searched
add_to_wishlistweb.wishlisted

ga4_purchase is read as purchase, and virtualPageView as a page view. A cart id next to ecommerce (shopcart_id) is kept, and an item's PLU (item_identifier or priceLookupUnitNumber) is used as its id when the shop sends one.

To identify from the data layer instead of calling cfcrm, push { event: 'cfcrm_identify', user: { email: '…' } }. An e-commerce event with GA4 user_data.email identifies the visitor too (with marketing consent); the email is never stored as event data.

Event fields

Every website event carries the same fields, so segments and automation conditions can use them:

FieldType
url, title, referrertextThe page it happened on
value, currencynumber, textFrom ecommerce.value / currency
transaction_idtextOrder number on purchase / refund
cart_idtextThe shop's cart id, when it sends one
item_ids, item_namestextComma-separated, from ecommerce.items
itemsjsonThe items as sent
search_termtextOn search
propsjsonAnything else you sent

Identifying visitors

A visitor is matched to a contact, in this order:

  1. A CRM email link. Links in your campaign and automation emails that point to one of the website's allowed domains get a signed, short-lived cf_ct parameter. The tracker reads it, removes it from the address bar, and identifies the visitor as the contact who clicked. Links to other sites never get it. In test mode this works for the emails in the Test outbox too: open one, click a link to your shop, and your visit is tied to that contact, so you can try the whole email → shop → cart reminder loop before going live. The click itself is not counted in the email's stats.
  2. externalId: your shop's customer id, matched against contacts' external id.
  3. email: an existing contact with that email, or a new one (source website) if Create contacts for new emails is on. This includes the GA4 user_data.email on an e-commerce event.
  4. The order. A purchase from a visitor who is still anonymous is matched by its transaction_id to your orders in the CRM, by Order number or Purchase number. If the order is linked to a contact, that contact is the buyer. Orders from an integration often arrive a few minutes after the purchase, so the CRM keeps trying for two days. If the number matches orders of more than one contact, nobody is identified.

Identifying never changes an existing contact's details and never grants marketing consent. That still goes through your forms and double opt-in.

Abandoned cart

The CRM follows each cart and puts one cart.abandoned event on a known contact whose cart goes quiet, with the items, value and links. See Abandoned carts & Viskan setup.

Automations → New → Website abandoned cart is the older way: it starts on web.added_to_cart, waits for a web.purchased for up to four hours, and sends a reminder if none comes.

Privacy

  • Nothing is stored before consent, and no IP address or user agent is ever stored. Events are tied to a person only with marketing consent.
  • The only cookie is the first-party _cfcrm_vid visitor id, set after consent.
  • Anonymous visitors and their events are deleted after the website's retention period (30 days by default). Raw hits are kept for 90 days; events on timelines follow the contact.
  • Deleting or erasing a contact deletes their website visitors and hits too.
  • Page views are kept as raw hits and not put on timelines, unless you turn that on.

Limits

Events per request20
Request body64 KB
Per site key6 000 requests / minute
Per IP address240 requests / minute
Custom event types50 per organisation

Requests from domains not on the website's list are refused (403 origin_not_allowed); an unknown or disabled key gets 404 unknown_site_key. Known crawlers are ignored.

Debugging

The Live events list on each website shows the latest hits and what became of each: On timeline, Waiting for identity (the visitor is still anonymous), Raw hit, Identified, or Dropped with the reason. Open your site in another tab, accept cookies, and watch them arrive.

The websites themselves can be managed with the Website tracking endpoints in the API reference.