Skip to content

Javascript Tracking Client

You can use the JavaScript tracking client to track any application that supports JavaScript: for example, websites!

This guide will explain how you can use the JavaScript tracking client to customize the way some of the data Web analytics are registered in MVMCloud Analytics.

Finding the Tracking Code in MVMCloud Analytics

To find your website's tracking code, follow the steps below:

  • Log in to MVMCloud Analytics with your Administrator account;
  • Click on "Administration" (gear icon) in the top right menu;
  • Click on "Tracking Code" in the menu on the left (under the "Sites" menu);
  • Click on the "JavaScript Tracking" section;
  • Select the website you want to track;
  • Copy and paste the JavaScript tracking code into your pages, right after the opening <body> tag (or inside the <head> section).

javascript tracking code

The tracking code looks like this:

Tracking code

JavaScript Crawler Features

Custom page title

By default MVMCloud Analytics uses the HTML page title to track the page title, you can customize it using the setDocumentTitle function:


_paq.push(['setDocumentTitle', document.title]);
_paq.push(['trackPageView']);

If you follow multiple subdomains on the same website, you may want your page titles to be prefixed by the subdomain, making it easy to visualize traffic and data for each subdomain. You can do this simply: By default MVMCloud Analytics uses the HTML page title to track the page title, you can customize it using the setDocumentTitle function:


_paq.push(['setDocumentTitle', document.domain + "/" + document.title]);
_paq.push(['trackPageView']);

Advanced users can also dynamically generate the page name, for example using PHP:

_paq.push(['setDocumentTitle', "<?php echo $myPageTitle ?>"]);
_paq.push(['trackPageView']);

Custom page URL

By default, MVMCloud Analytics uses the current page URL as the page URL in reports. You can customize the page URL to track using the setCustomUrl function.


_paq.push(['setCustomUrl', 'https://seudominio.com/sua-nova-pagina-url']);

Trigger events manually

By default, MVMCloud Analytics tracks page views when JavaScript tracking code is loaded and executed on each page view.

However, in modern web applications, user interactions do not necessarily involve loading a new page. For example, when users click a JavaScript link, or when they click a tab (which triggers a JS event), or when interact with UI elements, you can still track these interactions with MVMCloud Analytics.

To track any user interaction or click with MVMCloud Analytics, you can manually call the trackEvent() JavaScript function. For example, if you want to track a click on a JavaScript menu, you could write:

<a href="#" onclick="_paq.push(['trackEvent', 'Menu', 'Catalog']);">Catalog page</a>

You can learn more about event tracking in this guide.

Manually trigger goal conversions

Targets in MVMCloud Analytics are defined as "matching" parts of the URL (starts with, contains, or regular expression match). You can also track goals for certain page views, downloads, or external link clicks.

In some situations, you may want to record conversions on other types of actions, for example:

  • When a user submits a form;
  • When a user stayed more than a certain period of time on the page;
  • When a user makes some interaction in your Flash application;
  • Once a user has submitted their cart and made payment: you can provide the tracking code MVMCloud Analytics to payment site that will record conversions in your MVMCloud Analytics database, with personalized conversion revenue

To trigger a goal conversion:


// Record the conversion for goal 1
_paq.push(['trackGoal', 1]);

You can also record a conversion for this goal with a custom recipe. For example, you can generate the call to trackGoal() dynamically to set the transaction revenue:

// Record conversion for goal 1 with custom recipe configured
_paq.push(['trackGoal', 1, <?php echo $cart->getCartValue(); ?>]);

Find more information in the goal tracking documentation.

Accurately measure time spent on each page

By default, when a user only visits one page view during a visit, MVMCloud Analytics assumes that the visitor spent 0 seconds on the site. This has some consequences:

  • When the visitor views only one page, the "Visit duration" will be 0 seconds;
  • When the visitor views more than one page, the last page viewed on the visit will have a "Time spent on page" of 0 seconds;

You can configure MVMCloud Analytics to accurately measure the time spent visiting. To better measure the time spent visiting, add the following to your JavaScript code:


// Accurately measure time spent on each visit
_paq.push(['enableHeartBeatTimer']);

The MVMCloud Analytics will then send requests to count the actual time spent visiting, as long as the user is actively viewing the page (i.e. when the tab is active and in focus). The HeartBeat request is executed when:

  • Switch to another browser tab after the current tab has been active for at least 15 seconds (can be configured, see below);
  • Navigating to another page within the same tab;
  • Closing the flap.

// Change how long the tab needs to be active to activate
// counted as viewed in seconds
// Requires a page to be viewed for at least
// 30 seconds for the HeartBeat request to be sent.
_paq.push(['enableHeartBeatTimer', 30]);

Ecommerce Tracking

MVMCloud Analytics enables advanced and powerful eCommerce tracking. Check out the Ecommerce Tracking documentation for Get more information about eCommerce reporting and how to set up eCommerce tracking.

Internal Search Tracking

MVMCloud Analytics offers an advanced site search analytics feature, allowing you to track how your visitors use the site's internal search engine. By default, MVMCloud Analytics can read URL parameters that will contain the search keyword. However, you can also register the site search keyword manually using the JavaScript function trackSiteSearch(...).

On your website, you would typically have a call to record page views through trackPageView(). On your search results page, you would call the trackSiteSearch(keyword, category, searchCount) function to log the internal search request. Note: the 'keyword' parameter is mandatory, but category and searchCount are optional.


_paq.push(['trackSiteSearch',
     // Keyword (keyword)
     "Banana",
     // Category. If you don't need category
     // set false in this field
     "Organic Food",
     // Number of results per page. Zero indicates
     // no results. Set this to false if you
     // don't need this field
     0
]);
// We recommend not calling trackPageView() in
// Search Result Pages
// _paq.push(['trackPageView']);

We also recommend setting the searchCount parameter as MVMCloud Analytics will specifically report "no result keywords", i.e. keywords that were searched but did not return any results. It's generally very interesting to know what users are looking for, but can't find (yet?) on your website.

Custom Dimensions

Custom dimensions are a powerful feature that allows you to track custom values for each visit and/or each action (page view, outlink, download). Before you can use a custom dimension, you need to configure at least one dimension, see the [how-to-create-custom-dimensions.md] guide. You will get a numeric ID for each configured custom dimension, which you can use to set a value for it.

Track a custom dimension in tracking requests

To track a value, simply specify the ID followed by a value:


_paq.push(['setCustomDimension', customDimensionId = 1, customDimensionValue = 'Member']);

Note that once a custom dimension is defined, the value will be used for all custom dimension requests. following tracking and may lead to inaccurate results if this is not desired. For example, if you follow a page view, the custom dimension value will also be tracked for each following event, outbound link, download etc. on the same page load. Calling this method will not trigger a trace request, instead The amounts will be sent along with the following tracking requests. To delete a custom dimension value after a tracking request call _paq.push(['deleteCustomDimension', customDimensionId]);

Defining a custom dimension for the home page view

To set a custom dimension for the home page display, be sure to position the setCustomDimensionantes method call of trackPageView:


_paq.push(['setCustomDimension', customDimensionId = 1, customDimensionValue = 'Member']);
_paq.push(['trackPageView']);
// _paq.push(['enableLinkTracking']);

Tracking a custom dimension for a specific action only

You can define a custom dimension only for a specific action. If you want to track a page view, You can send one or more specific custom dimension values along with this tracking request as follows:


_paq.push(['trackPageView', pageTitle, {dimension1: 'DimensionValue'}]);

To set a dimension value, pass an object defining one or several properties as the last parameter (make sure to specify all parameters as defined in the method, we do not automatically assume that the last parameter is customData, but all parameters that a method defines need to be passed to each method). The property name for a dimension starts with dimension followed by a custom dimension ID, for example dimension1. The same behavior applies to several other methods:


_paq.push(['trackEvent', category, action, name, value, {dimension1: 'DimensionValue'}]);
_paq.push(['trackSiteSearch', keyword, category, resultsCount, {dimension1: 'DimensionValue'}]);
_paq.push(['trackLink', url, linkType, {dimension1: 'DimensionValue'}]);
_paq.push(['trackGoal', idGoal, customRevenue, {dimension1: 'DimensionValue'}]);

The advantage is that the defined dimension value will be used only for this specific action and you will not need to delete the value after a tracking request. You can define multiple dimension values like this:


_paq.push(['trackPageView', pageTitle, {dimension1: 'DimensionValue',
             dimension4: 'Test', dimension7: 'Value'}]);

How to retrieve a custom dimension value


getCustomDimension(customDimensionId)

This function can be used to get the value of a custom dimension. It will only work if a custom dimension was defined while loading the same page.

User ID

User ID is a feature of MVMCloud Analytics that allows you to connect a given user's data collected from multiple devices and browsers. There are two steps to implementing User ID:

  • You must assign a unique and persistent non-empty string that represents each logged in user. Typically, this ID This will be an email address or username provided by your authentication system.
  • You must set the user ID for each page view, otherwise the page view will be tracked without the user ID set.
  • You must then pass this user ID string to MVMCloud Analytics via the setUserId method call before calling any of the track* functions ( trackPageview, trackEvent, trackGoal, trackSiteSearch, etc.) for example:

_paq.push(['setUserId', 'ID_DO_USUARIO_AQUI']);
_paq.push(['trackPageView']);

Note: USER_ID_HERE must be a unique and persistent non-empty string that represents a user across multiple devices.

When the user is logged in, set the user ID

Let's take an example. Imagine that your website authenticates your users through a login form using a PHP script. Here's an example of how to define your JavaScript snippet:

var _paq = window._paq = window._paq || [];
<?php
// If the user is logged-in, execute 'setUserId'
// The $userId variable must be defined by the server when
// the user authenticates.
if (isset($userId)) {
      echo sprintf("_paq.push(['setUserId', '%s']);", $userId);
}
?>
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);

When user logs out, reset user ID

When the user has logged out and a user ID is no longer available, it is recommended to notify MVMCloud Analytics calling the resetUserId method before trackPageView.

If you want to create a new visit when users log out, you can also force MVMCloud Analytics to create a new one visit by calling resetUserId and appendToTrackingUrl (twice) as below:


// The user has just logged out, the User ID needs to be reset
_paq.push(['resetUserId']);

// It is necessary to force a new visit to be registered after logout
_paq.push(['appendToTrackingUrl', 'new_visit=1']);

_paq.push(['trackPageView']);

// Finally, make sure you don't continue creating new visits from now on
_paq.push(['appendToTrackingUrl', '']);

Content Tracking

There are several ways to track impressions and content interactions manually, semi-automatically, and automatically. Please be aware that content impressions will be tracked using bulk tracking, which will always send a POST request, even if GET is set as default. For more details, see the detailed guide on content tracking.

Track all content impressions on a page

You can use the trackAllContentImpressions() method to scan the entire DOM for content blocks. For each content block, we will track a content impression immediately. If you just want to track viewable content impression, take a look at trackVisibleContentImpressions().


_paq.push(['trackPageView']);
_paq.push(['trackAllContentImpressions']);

We will not print the same content block twice if you call this method multiple times, unless trackPageView() is called in the meantime. This is useful for single-page applications.

Track only content impressions visible on a page

Enable to track only visible content impressions via trackVisibleContentImpressions(checkOnScroll, timeIntervalInMs). By visible, we mean that the content block has been in the viewport and is not hidden (opacity, visibility, display, ...).

  • Optionally, you can tell it not to recheck the DOM after each scroll by passing checkOnScroll=false. Otherwise, it will be checked whether previously hidden content blocks became visible after a scroll, and if so, the impression will be tracked.
  • Limitation: If a block of content is placed inside a scrollable element (overflow: scroll), we currently do not detect when such an element becomes visible.
  • Optionally, you can instruct us to rescan the entire DOM for new content impressions every X milliseconds by passing timeIntervalInMs=500. By default, we will recheck the DOM every 750 ms. To disable it, pass timeIntervalInMs=0.
  • Re-scanning the entire DOM and detecting the visible state of content blocks may take a while depending on the browser, hardware and amount of content. If your frames per second decrease, you can increase the interval or disable it completely. In case you disable it, you can still recheck the DOM manually at any time by calling this method again or trackContentImpressionsWithinNode().

Both checkOnScroll and timeIntervalInMs cannot be changed after this method has been called for the first time.


_paq.push(['trackPageView']);
_paq.push(['trackVisibleContentImpressions', true, 750]);

Track content impressions for only part of the page

Use the trackContentImpressionsWithinNode(domNode, contentTarget) method if you are adding elements to your DOM after let's track initial impressions. Calling this method will ensure that an impression is tracked for all content blocks contained in this node.

Example:

var div = $('<div>...<div data-track-content>...</div>...<div data-track-content>...</div></div>' );
$('#id').append(div);
_paq.push(['trackContentImpressionsWithinNode', div[0]]);

We would detect two new content impressions in this example. If you have enabled tracking for visible content blocks only, we will respect that.

Track a semi-automatic interaction

Interactions with content blocks are usually automatically tracked once a visitor clicks on it. Sometimes you may want to trigger an interaction manually, for example, if you want to trigger an interaction based on submitting a form or double-clicking. To do this, call the trackContentInteractionNode(domNode, contentInteraction) method.

Example:

formElement.addEventListener('submit', function () {
_paq.push(['trackContentInteractionNode', this, 'submittedForm']);
});
  • The passed domNode can be any node within a content block or the content block element itself. Nothing will be tracked if no content blocks are found.
  • Optionally, you can define the name of the content interaction, for example click or submit. If none is provided, the Unknown value is used.
  • You must disable automatic interaction tracking for this content block by defining the piwikContentIgnoreInteraction CSS class or the data-content-ignoreinteraction attribute. Otherwise, an interaction can be tracked as soon as a visitor clicks.

We call this type of tracking semi-automatic because you triggered the interaction manually, but the content name, part, and destination are detected automatically. Automatic detection of the name and content piece ensures we can map the interaction to a previously tracked impression.

Tracking impressions and content interactions manually

You must use the trackContentImpression(contentName, contentPiece, contentTarget) and trackContentInteraction( contentInteraction, contentName, contentPiece, contentTarget) methods only when they are together. It is not recommended to use trackContentInteraction() after an impression has been automatically tracked, as we may map an interaction to a impression only if you define the same content and part name that was used to track the related impression.

Example

_paq.push(['trackContentImpression', 'Content Name', 'Content Piece', 'https://www.example.com']);

div.addEventListener('click', function () {
_paq.push(['trackContentInteraction', 'tabActivated', 'Content Name', 'Content Piece', 'https://www.example.com']);
});

Be aware that each call to these methods will send a request to your MVMCloud Analytics tracker instance. Doing so can often cause performance issues.

Measuring Domains and/or Subdomains

If you are tracking a domain or a subdomain, or both at the same time, you may need to configure the MVMCloud Analytics JavaScript tracking code. There are two things that may need to be configured: 1) how tracking cookies are created and shared and 2) which clicks should be tracked as 'Outbound Links'.

Tracking a domain

This is the default use case. MVMCloud Analytics tracks visits from a domain name without a subdomain, to a single MVMCloud Analytics site.

// Default tracking code
_paq.push(['setSiteId', 1]);
_paq.push(['setTrackerUrl', u+'js/tracker.php']);
_paq.push(['trackPageView']);

If you are tracking a specific subdomain, this default tracking code will also work.

Tracking a domain and its subdomains on the same website

To register users on the main domain name and any of its subdomains, we tell MVMCloud Analytics to share cookies on all subdomains. setCookieDomain() is called in the tracking code for MVMCloud Analytics on example.com/* and all subdomains.

_paq.push(['setSiteId', 1]);
_paq.push(['setTrackerUrl', u+'js/tracker.php']);

// Share the tracking cookie between
// example.com, www.example.com, subdomain.example.com, ...
_paq.push(['setCookieDomain', '*.example.com']);

// Enter the website domain, then click on them
// domains will not be tracked as 'External Links'
_paq.push(['setDomains', '*.example.com']);

_paq.push(['trackPageView']);

Tracking your visitors across multiple domain names on the same website

To accurately track a visitor across different domain names in a single visit to a MVMCloud Analytics website, we need set up what is called a cross-domain link. MVMCloud Analytics cross-domain tracking ensures that when the visitor visit multiple websites and domain names, visitor data is stored on the same visit and the visitor ID is reused in domain names. A typical use case where cross-domain is required is, for example, when a ecommerce online store is live www.awesome-shop.com and ecommerce shopping cart technology is on another domain, such as secure.cart.com.

Cross-domain linking uses a combination of the two tracking methods setDomains and enableCrossDomainLinking. Find out how to configure linking between domains in our guide: How to accurately measure the same visitor across multiple domain names (linking between domains)?

Crawl subdirectories of a domain across separate sites

When tracking subdirectories of a domain in its own separate site in MVMCloud Analytics, it is recommended that you customize the tracking to ensure optimal data accuracy and performance.

For example, if your website offers a 'User Profile' functionality, you may want to track each profile page username in a separate site in MVMCloud Analytics. On the main domain homepage, you would use the default tracking code:

// idSite = X for Homepage
// In Administration > Sites for idSite=X, the URL is set to `example.com/`
_paq.push(['setSiteId', X]);
_paq.push(['setTrackerUrl', u+'js/tracker.php']);
_paq.push(['trackPageView']);

On the example.com/user/MyUsername page (and all other user profiles), you would construct calls to custom setSiteId, setCookiePath, and setDomains.

// idSite Y will be different from other user pages
// In Administration > Sites for idSite=Y, the URL is configured
// for `example.com/user/MyUsername`
_paq.push(['setSiteId', Y]);

// Creates the tracking cookie specifically at `example.com/user/MyUsername`
_paq.push(['setCookiePath', '/user/MyUsername']);

// Tells MVMCloud Analytics the website domain, thus,
// clicks on other pages will be tracked as
// "External links" (ex: /user/AnotherUsername)
_paq.push(['setDomains', 'example.com/user/MyUsername']);

_paq.push(['setTrackerUrl', u+'MVMCloud Analytics.php']);
_paq.push(['trackPageView']);

When tracking many subdirectories across separate sites, the setCookiePath function prevents the number of cookies from increasing quickly and prevents the browser from deleting some of the cookies. This ensures optimal data accuracy and improves the performance of your users (fewer cookies are sent with each request).

The setDomains function ensures that clicks from users leaving your site (example.com/user/MyUsername subdirectory) are tracked correctly as 'External Links'.

Crawling a Group of Pages on a Separate Site

In some rare cases, you may want to track all pages that match a wildcard in a given website and track clicks to other pages (that do not match the wildcard) as 'External Links'.

On the pages /index_fr.htmor /index_en.htm write:

// clicks on links that don't start with
// example.com/index will be crawled as 'External Links'
_paq.push(['setDomains', 'example.com/index*']);

// when using a wildcard *, there is no need to configure
// cookies with `setCookieDomain`
// or `setCookiePath`, because cookies are created
// correctly on the main domain by default.

_paq.push(['setTrackerUrl', u+'js/tracker.php']);
_paq.push(['trackPageView']);

Grades:

  • The * wildcard is only supported when specified at the end of the string.
  • Because the wildcard can match multiple paths, setCookieDomain or setCookiePath calls are omitted to ensure that the tracking cookie is shared correctly to all pages matching the wildcard.

The default JavaScript tracker code of MVMCloud Analytics is automatically enabled for download and external link tracking, what is done by calling the enableLinkTracking function:

_paq.push(['enableLinkTracking']);

It is recommended to add this line right after the first call to trackPageView or trackEvent.

By default, all links to domains other than the current domain have click tracking enabled and each click will be counted as an external link. If you use multiple domains and subdomains, you may see clicks to your subdomains appearing in the Behavior > External Links menu.

If you want only clicks to external sites to appear in your external links report, use the setDomains() function to Specify the list of domain or subdomain aliases. Wildcard domains (*.example.org) are supported to allow you easily ignore clicks on all subdomains.

// Do not track external links on all clicks that point to *.hostname1.com or *.hostname2.com.
// Note: The currently crawled site is added to this set automatically.
_paq(['setDomains', ["*.hostname1.com", "hostname2.com"]]);

_paq.push(['trackPageView']);

You can also append a path to a domain and MVMCloud Analytics will correctly detect links to the same domain but different paths as an external link.

// Do not track external links on all clicks to
// *.hostname1.com/product1/* or *.hostname2.com/product1/*
// Track all clicks that don't point to
// *.hostname1.com/product1/* or *.hostname2.com/product1/* as outlink.
_paq(['setDomains', ["*.hostname1.com/product1", "hostname2.com/product1"]]);

Learn more about this use case Crawl subdirectories of a domain across separate sites .

If you want to force MVMCloud Analytics to consider a link as an external link (links to the current domain or one of the domain aliases), you can add css class piwik_link to the link:

<a href='https://mysite.com/partner/' class='piwik_link'>Link that I want to track as an external link</a>

Note: You can customize and rename the CSS class used to force a click to be registered as an external link:

// Now all clicks on links with the class "external" will be counted as an external link.
// You can also pass it as a string string
_paq.push(['setLinkClasses', "external"]);
_paq.push(['trackPageView']);

Alternatively, you can use JavaScript to manually trigger a click on an external link (it will work the same form for page views or file downloads). In this example, the custom extern link is triggered when the email address is clicked:

<a href="mailto:[email protected]" target="_blank" onClick="_paq.push(['trackLink', 'https://mydomain.co.uk/mailto/Agent namexyz', ' link']);">[email protected] </a>

File Download Tracking

By default, any file ending with one of these extensions will be considered a 'download' in the MVMCloud Analytics interface:

7z|aac|arc|arj|apk|asf|asx|avi|bin|bz|bz2|csv|deb|dmg|doc|
exe|flv|gif|gz|gzip|hqx|jar|jpg|jpeg|js|mp2|mp3|mp4|mpg|
mpeg|mov|movie|msi|msp|odb|odf|odg|odp|ods|odt|ogg|ogv|
pdf|phps|png|ppt|qt|qtm|ra|ram|rar|rpm|sea|sit|tar|
tbz|tbz2|tgz|torrent|txt|wav|wma|wmv|wpd||xls|xml|z|zip

Customize the type of files tracked as downloaded

To override the list of extensions you want to track as file downloads, you can use setDownloadExtensions(string):

// Now only image clicks will be tracked
_paq.push(['setDownloadExtensions', "jpg|png|gif"]);
_paq.push(['trackPageView']);

If you want to track a new file type, simply add it to the list using addDownloadExtensions(filetype):

// Clicks on URLs ending in mp5 or mp6 will be counted as downloads
_paq.push(['addDownloadExtensions', "mp5|mp6"]);
_paq.push(['trackPageView']);

If you want to ignore a special file type, simply remove it from the list using removeDownloadExtensions(filetype):

// Clicks on URLs ending in png or mp4 will not be counted as downloads
_paq.push(['removeDownloadExtensions', "png|mp4"]);
_paq.push(['trackPageView']);

Registering a Click as a Download

If you want to force MVMCloud Analytics to consider a link as a download, you can add the piwik_download css class to the link:

<a href='last.php' class='piwik_download'>Link I want to track as a download</a>

Note: You can customize and rename the CSS class used to force a click to register as a download:

// Now all clicks on links with the "download" css class
// will be considered as downloads.
// You can also pass an array of strings
_paq.push(['setDownloadClasses', "download"]);
_paq.push(['trackPageView']);

Alternatively, you can use JavaScript to manually trigger a click on a download. In this example, the custom download is triggered when the link is clicked:

<a href="https://secure.example.com/this-is-a-file-url" target="_blank"
    onClick="_paq.push(['trackLink', 'https://mydomain.co.uk/mailto/Agent namexyz', 'download']);">Download</a>

Change the Pause Timer

When a user clicks to download a file or clicks an exit link, MVMCloud Analytics registers it. For that, adds a small delay before the user is redirected to the requested file or link. The default value is 500 ms, but you can set it to a shorter period of time. Please note, however, that in doing so you run the risk of this period of time is not enough for the data to be registered in MVMCloud Analytics.

_paq.push(['setLinkTrackingTimer', 250]); // 250 milliseconds
_paq.push(['trackPageView']);

By default, the MVMCloud Analytics tracking code allows clicks and download tracking. To disable all tracking automatic download and external link, you must remove the call to the enableLinkTracking() function:

_paq.push(['trackPageView']);

// Comment out the call that enables link tracking
// _paq.push(['enableLinkTracking']);

Disabling for Specific CSS Classes

You can disable automatic download and external link tracking for links with specific CSS classes:

// You can also pass ym array of strings
_paq.push(['setIgnoreClasses', "no-tracking"]);
_paq.push(['trackPageView']);

This will result in clicks on a Test link not being counted.

If you want to ignore download or external link tracking on a specific link, you can add 'piwik_ignore' css class to it:

<a href='https://builds.MVMCloud Analytics.org/latest.zip' class='piwik_ignore'>File I don't want to be tracked as a download</a>

The collection and processing of personal data is regulated by specific laws and regulations, MVMCloud Analytics has tools that enable compliance in relation to these laws. See how MVMCloud Analytics complies:

  1. Brazilian LGPD (General Personal Data Protection Law);
  2. European GDPR (General Data Protection Regulation).

Custom cancellation

If you want to provide your users with the ability to opt out of tracking entirely, use an opt-out form. O MVMCloud Analytics comes with an opt-out form implementation that uses third-party cookies (which you can configure in MVMCloud Analytics on the Administration >> Privacy page).

This form is simple to embed as it only requires you to add an iframe to your website, but it's not always ideal. Some users block third-party cookies making the opt-out form not work for them. You may also want to display custom text, or graphics on the opt-out form, or allow users to opt-out of their sites individually rather than all.

In this case, you may want to use a custom opt-out form. The specifics of creating an HTML/JS form are outside the scope of this document, but there are a few things that every custom opt-out form will have to do: verify that the user is currently excluded from tracking, exclude a user, and include a user in tracking. Here's an example of how to do it:

Check if the user is currently excluded from tracking

Use the isUserOptedOut() method like this:

_paq.push([function () {
   if (this.isUserOptedOut()) {
     // ...modify the form to inform the user that they are already excluded from tracking...
   } else {
     // ... modify the form to inform the user that they are already included in the tracking ...
   }
}])

Exclude a user from tracking

Use the optUserOut() method:

_paq.push(['optUserOut']);

Add a tracking user

Use the forgetUserOptOut() method:

_paq.push(['forgetUserOptOut']);

Below is an example deactivation form that replicates MVMCloud Analytics's built-in deactivation form:

<div id="optout-form">
   <p>You can opt out of having a unique web analytics cookie identification number assigned to your computer to prevent the aggregation and analysis of data collected on this website.</p>
   <p>To make this choice, click below to receive an opt-out cookie.</p>

   <p>
     <input type="checkbox" id="optout" />
     <label for="optout"><strong></strong></label>
   </p>
</div>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
   function setOptOutText(element) {
     _paq.push([function() {
       element.checked = !this.isUserOptedOut();
       document.querySelector('label[for=optout] strong').innerText = this.isUserOptedOut()
         ? 'You are currently excluded from tracking. Click here to be included.'
         : 'You are currently included in tracking. Click here to be deleted.';
     }]);
   }

   var optOut = document.getElementById("optout");
   optOut.addEventListener("click", function() {
     if (this.checked) {
       _paq.push(['forgetUserOptOut']);
     } else {
       _paq.push(['optUserOut']);
     }
     setOptOutText(optOut);
   });
   setOptOutText(optOut);
});
</script>