Group ties a visitor to a company and records the company's name and traits, so Company-based attribution can credit conversions to the company.
Warning!
- The JavaScript API (Client-Side) articles are intended for developers!
- Attribution should be installed by a developer.
- Installing Attribution with Google Tag Manager is possible but not recommended.
- Do not minify or bundle Attribution snippet inside a webpack or it may render unstable in some conditions.
- Please try to avoid putting snippet inside a JS closure. You are still free to call
group()from inside your JS app usingwindow.Attributionvariable.
Group ties the current visitor to a company: an account, workspace or organization that several of your users share. Call it once you know which company the visitor belongs to, for example after they sign in. Company-based attribution then credits conversions to the company rather than to each person.
Attribution.group(groupId, [traits], [callback]);| Parameter (type) | Description |
|---|---|
| groupId String, required | The company's ID in your database, up to 64 bytes. Every visitor grouped under the same ID belongs to the same company. |
| traits Object, optional | A hashtable of traits describing the company. name is the name the dashboard shows for the company; the other traits are saved with it. |
| callback Function, optional | A callback function that gets called after a short timeout. |
Attribution.group('c_2207', {
name: 'Stoa Labs',
plan: 'Enterprise',
employees: 120
});How companies are updated
- The company is created the first time Attribution sees its
groupId; later calls with the samegroupIdupdate it. - Each call updates only the traits it includes; traits you leave out keep their stored values. A later value replaces an earlier one, and inside an object trait each key is updated on its own:
address: { city: 'Rome' }changes only the city. - The snippet remembers the company's traits in the browser and sends all of them with every
group()call, so a trait your server changed in the meantime is set back to the browser's value. Send each trait either from the browser or from your server, not both. - A visitor belongs to one company at a time. A
group()call with a differentgroupIdmoves the visitor to that company. - Called with traits but no
groupId, as ingroup({ plan: 'Enterprise' }), or withundefinedin its place,group()updates the company the visitor was last grouped into on that device, and is ignored if there is none. Check that the ID is set before you call it, so one company's traits do not land on another. - A placeholder
groupIdsuch as0,'null'or'undefined'is ignored.
Group and the company trait of identify
The company trait of identify ties a user to a company just as group() does: identify('u_8841', { company: { id: 'c_2207', name: 'Stoa Labs' } }) moves the user to company c_2207 exactly like group('c_2207', { name: 'Stoa Labs' }). Use whichever call fits your app.
The most recent of the two calls decides the user's company. If your app and a connected CRM name different companies for the same user, the user moves with each call. After a group() call, the user's company trait holds the company's id and name. To remove a user from their company, call identify() with company: null.
