Envive Analytics SDK
We provide a lightweight SDK for reporting specific events on the frontend to Envive.
Quick Start
Install the SDK via npm/yarn or use the CDN snippet
Get your API key from the Envive team (
ENVIVE_PUBLIC_KEY)Identify users with
identifyUser()OR passidentityOptionswith every tracking callTrack events like checkout completion and add-to-cart actions
Pre-Launch Checklist
Installation
To install @envive-ai/analytics Install as follows:
You can install the SDK using a small snippet of code added to your site via Google Tag Manager (GTM) to load the SDK asynchronously.
Create an HTML tag in GTM to be added to every page where you need to track the events, replacing ENVIVE_PUBLIC_KEY with your public key (provided by us).
You can install the SDK using a small snippet of code added directly to your site to load the SDK asynchronously.
Put the following on every page where you need to track the events, just before the </head> tag, replacing ENVIVE_PUBLIC_KEY with your public key (provided by us).
Usage
NPM/Yarn Usage
CDN Usage
User Identification
Choose one approach (required):
Call
identifyUser()once when the user is recognized and before calling any tracking methods
OR
Pass
identityOptionswith every tracking call
⚠️ Critical: If users are not properly identified, events cannot be attributed and analytics will not work.
User ID Guidelines
Requirements (for both methods):
Use a stable, persistent ID from your platform (never random UUIDs)
Always include
idTypeto describe where the ID came from. See idType for more information.
Correct ID sources:
✅ Shopify clientId
✅ Internal platform user ID
✅ BigCommerce SHOP_SESSION_TOKEN
✅ Magento customer_id (if configured to persist long-term)
Incorrect ID sources:
❌ Random UUIDs
❌ Session IDs
❌ Cart IDs
❌ Auto-generated values
idType
idType is a descriptive label for the user ID you send to Envive. It is highly recommended to provide an idType value to maintain unique ID namespaces.
Set idType to a kebab-case string that describes where the ID came from, such as:
shopify-client-idmagento-user-idcrm-user-id
Method 1: identifyUser() (Recommended)
Call once before any tracking calls. The id that you choose must not change for the lifetime of the user.
See User ID Guidelines and idType for more information on how to use these parameters.
Method 2: identityOptions Parameter
If you are not using identifyUser(), include this object with every tracking call:
See User ID Guidelines and idType for more information on how to use these parameters.
Using identifyUser() Without Shopify
If your platform is not on Shopify, you must pass the stable user ID that your platform already uses.
Examples:
CRM user ID
Internal platform account ID
Authentication system user ID
Do not use session IDs, cart IDs, browser-generated IDs, or random UUIDs.
See User ID Guidelines and idType for more information on how to use these parameters.
Event Tracking Methods
Note: If not using
identifyUser(), includeidentityOptionswith every tracking call.
trackCheckoutComplete
When a user completes a purchase, it is typically triggered on the thank-you page.
Equivalent to Shopify checkout_completed event.
⚠️ IdentityOptions Required (if identifyUser is not used)
Important: If you do not call identifyUser() before any track events, you must include the identityOptions argument with every single tracking call. Failing to do so will cause attribution to break.
trackAddToCartClicked
When a user adds a product to their cart.
Equivalent to the Shopify product_added_to_cart event.
⚠️ IdentityOptions Required (if identifyUser is not used)
Important: If you do not call identifyUser() before any track events, you must include the identityOptions argument with every single tracking call. Failing to do so will cause attribution to break.
trackCustomConversion
Used to track a non-standard conversion defined by the merchant.
⚠️ IdentityOptions Required (if identifyUser is not used)
Important: If you do not call identifyUser() before any track events, you must include the identityOptions argument with every single tracking call. Failing to do so will cause attribution to break.
trackPageViewed
⚠️ IdentityOptions Required (if identifyUser is not used)
Important: If you do not call identifyUser() before any track events, you must include the identityOptions argument with every single tracking call. Failing to do so will cause attribution to break.
Common Mistakes
Most frequent integration issues:
Missing
identifyUser()- Events can't be linked across sessionsRandom UUIDs - Creates new "users" every page load
Late identification - Events before
identifyUser()won't be attributedUnstable IDs - Don't use session/cart IDs or localStorage values
Platform confusion - Use your platform's actual user ID, not Shopify-specific IDs on other platforms
Server Side Usage
Note: When using the analytics SDK server-side, an enviveUserId is neither present nor required in any SDK API call methods.
However, it is critical that:
IdentifyUseris called somewhere in the user's client-side journey (on your website)All
Track__Methods are supplied with theidentityinformation
To Summarize:
IdenfiyUser or Track____ method call with identity payload included
Website
IdenfiyUser or Track with identity included must be called at least once in the user's client-side journey
Track____ methods only. No IdentifyUser calls necessary.
Server Side (eg: Lambda functions, Azure Functions, ECS Tasks etc)
Call as needed to instrument events such as "Checkout Begin", "Checkout Complete" or "Commerce Transaction Complete" and always include the identity parameter
Example Implementations
Check out the example minimal implementations of using this SDK.
Shopify Hydrogen
React
Last updated