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
- You add a website under Settings → Website tracking and get a public site key (
cfs_…). - 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. - Events from an anonymous visitor are kept, not put on any timeline.
- 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.
- 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
- In Settings → Website tracking, add your website with the domains it runs on, and download the tag template.
- In GTM: Templates → Tag templates → New → ⋮ → Import, pick
code-fab-crm.tpl, save. - Tags → New → Code F CRM, action Load the tracker, paste the site key. Fire it on Consent Initialization – All Pages (or Initialization – All Pages).
- 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.
- 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:
<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:
cfcrm('consent', true); // statistics and marketingcfcrm('consent', true, { marketing: false }); // statistics only: nobody is namedcfcrm('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.
Consent
- 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:
| Source | Statistics | Marketing |
|---|---|---|
| Google Consent Mode | analytics_storage | ad_user_data (else ad_storage) |
| Cookiebot | Cookiebot.consent.statistics | Cookiebot.consent.marketing |
| Cookie Information | cookie_cat_statistic | cookie_cat_marketing |
| Your own banner | cfcrm('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
| Command | What 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:
| Option | Default | |
|---|---|---|
consent | 'required' | 'required' waits for consent; 'granted' starts straight away. |
dataLayer | true | Read GA4 events and consent from the data layer. |
dataLayerName | 'dataLayer' | If your data layer has another name. |
pageViews | true | Send 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:
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 event | CRM event |
|---|---|
page_view | web.page_viewed |
view_item | web.product_viewed |
view_item_list | web.list_viewed |
select_item | web.product_selected |
add_to_cart / remove_from_cart | web.added_to_cart / web.removed_from_cart |
view_cart | web.cart_viewed |
cart_update (the full cart after a change) | web.cart_updated |
begin_checkout | web.checkout_started |
add_shipping_info / add_payment_info | web.shipping_added / web.payment_added |
purchase / refund | web.purchased / web.refunded |
sign_up / login | web.signed_up / web.logged_in |
generate_lead | web.lead_submitted |
search | web.searched |
add_to_wishlist | web.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:
| Field | Type | |
|---|---|---|
url, title, referrer | text | The page it happened on |
value, currency | number, text | From ecommerce.value / currency |
transaction_id | text | Order number on purchase / refund |
cart_id | text | The shop's cart id, when it sends one |
item_ids, item_names | text | Comma-separated, from ecommerce.items |
items | json | The items as sent |
search_term | text | On search |
props | json | Anything else you sent |
Identifying visitors
A visitor is matched to a contact, in this order:
- 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_ctparameter. 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. externalId: your shop's customer id, matched against contacts' external id.email: an existing contact with that email, or a new one (sourcewebsite) if Create contacts for new emails is on. This includes the GA4user_data.emailon an e-commerce event.- The order. A
purchasefrom a visitor who is still anonymous is matched by itstransaction_idto 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_vidvisitor 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 request | 20 |
| Request body | 64 KB |
| Per site key | 6 000 requests / minute |
| Per IP address | 240 requests / minute |
| Custom event types | 50 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.