Installing multiple Usermaven scripts

How to install multiple Usermaven scripts on a single website

After the initial sign-up on Usermaven, the first step is to create a workspace. The subsequent step involves the integration of your website or SaaS app with Usermaven. To achieve this, you'll need to incorporate a tracking script into the Header (<head></head>) section of your website.

It is worth noting that users can incorporate multiple tracking scripts from distinct workspaces onto their websites. In this guide, you’ll learn to add multiple tracking scripts to your website, enabling the tracking and visualization of data across various workspaces.

Installing multiple scripts using namespaces

Installing a single tracking script on your website is super easy. A detailed guide for this can be found on the Installing Usermaven (opens in a new tab) page.

If you're dealing with multiple scripts, you’ll add the data-namespace attribute to your script. These unique namespaces, assigned to each script, allow for the creation of separate contexts and clear identification of individual workspaces's pixels.

Below is a code sample:

 
<!-- Initializing Usermaven tracking code for the first workspace -->
<script src="https://t.usermaven.com/lib.js" data-key="WORKSPACE_API_KEY_1" data-privacy-policy="strict"></script>
 
<!-- Initializing Usermaven tracking code for the second workspace -->
<script src="https://t.usermaven.com/lib.js" data-key="WORKSPACE_API_KEY_2" data-namespace="um"></script>
 

Once operational, the scripts will start tracking the page views and auto-captured events (if enabled) to Usermaven.

In scenarios where multiple scripts are in operation, the identify function needs to be executed for each relevant script. For instance, while the standard usermaven.id would be used for the first script, for the subsequent one, um.id would be invoked.

<!-- Identifying across the two workspaces -->
usermaven.id({
    // user or company data
});
um.id({
    // user or company data
});
 
<!-- Tracking activities across the two workspaces -->
usermaven.track("activity1");
um.track("activity2");

Always remember that "WORKSPACE_API_KEY_1" and "WORKSPACE_API_KEY_2" are placeholders that must be replaced with your own specific workspace keys. Furthermore, "activity1" and "activity2" need to be replaced with actual user activities that you intend to track. Make sure to use distinctive text for individual namespaces to simplify tracking and data understanding.