Install JavaScript snippet

  • Updated

Analytics in Optimizely Content Marketing Platform (CMP) are content-centric, which means that they can provide granular, meaningful insights from your content in a way that typical site analytics cannot, offering more visibility and better data so you can make the best decisions for your content marketing strategy.

Add a small script in the header of your article pages. Optimizely tracks engagement for each page containing content, which includes any format.

Install CMP's JavaScript snippet

Your unique JavaScript snippet is at your avatar > Organization > Misc. tab > Analytics Tracking Snippet section.


Copy the snippet and install it to your site in one of the following ways:

Add the snippet via a CMS

Log into your CMS and access your site’s HTML code. Paste your snippet (unaltered and in its entirety) into the site header immediately before the closing </head> tag.

Some CMS’s have a separate section where you can add a tracking code. If you are unsure of your site's specific configuration, contact your web production or development team. Contact Support if you have any questions or require additional assistance.

Add the snippet via WordPress

There are two easy ways to add the tracking code to WordPress:

  • Option 1: Plugins (Recommended). There are a variety of plug-ins available to add custom header and footer codes to your site. A simple, light-weight plug-in that you should use is Insert Headers and Footers. Paste your tracking code snippet into the header on the plugin's settings page.
  • Option 2: Paste directly into the header. Open up the editor for the header.php file. Paste the snippet right before the closing </head> tag.

Add the snippet via Google Tag Manager

Follow these instructions only if you already have a working configuration of Google Tag Manager (GTM) on your website. This means you have copied and pasted your GTM’s code snippets into your website as instructed in the Install Tag Manager dialog box. See instructions on Google’s Support site.

  1. From your GTM container, click New.


  2. Give your new tag a name and set Tag Type to Custom HTML.
  3. In the HTML field, paste your unique analytics snippet (including the opening and closing <script> tags).
  4. In the Triggering section at the bottom, add a Firing Trigger for All Pages.


  5. Click Save.
  6. Click Submit on the main workspace page to push the tag (Welcome JS).
  7. Include Version Name and Description and click Publish to complete.

Answers to CMP JavaScript questions

Is CMP JavaScript safe to install?

CMP's JavaScript is SOC2-compliant and works with some of the world’s largest and most highly-regulated companies. Our JavaScript, in conjunction with the embedded pixel, tracks unique IP addresses and cookie IDs of visitors to your website. This lets us glean content-centric performance metrics, such as engagement, scroll length, time on site, etc. We encrypt this data and store it securely. Rest assured, we are GDPR-compliant and Privacy Shield-certified.

Will this impact the performance of my site?

The JavaScript script loads from a CDN and is only 7.5KB in size. It also loads asynchronously, so page load speeds should not be impacted by placing the script in the header. However, if your team has multiple scripts in the header, you can also place the script in the footer with little-to-no impact on load time or tracking.

Does the JavaScript interfere with my other analytics tools?

Embedding the JavaScript creates no conflicts with Google Analytics or Adobe Analytics. The JavaScript uses a unique Google Analytics tracker name, so it cannot conflict with another Google Analytics tracker on the page. We believe that Google Analytics or Adobe Analytics and CMP’s analytics complement each other. We believe that in any decision-making process the more data you can gather, the better.

How should I deploy JavaScript in a cookie consent setup?

If you are using the cookie consent plugin, then it is best to only load the Analytics JavaScript after the user has confirmed that they consent to cookies being used. The exact configuration varies depending on your cookie consent tool. Contact if you have any questions or require assistance.

What is a tracking pixel?

A tracking pixel is a code that uses a single pixel to track different user engagements through an HTML img tag. The code is inserted into the pages of third-party websites right below the article's description. The pixel activates a request when a visitor loads the page and the request is logged as a page view.

Why does CMP use tracking pixels?

The tracking pixel collects data by activating when the page loads. It can count pageviews and unique visitors. The following example shows the tracking pixel:

<img src=""

Tracking pixels vary by URL. You can see them from any tasks that are also opened from the "Tasks" section.

Go to any of your tasks, open the options menu (...) > More > Copy Tracking Pixel to copy it onto your clipboard.


The tracking pixel is embedded into your site on pages where articles from CMP are published. To verify, make sure the tracking pixel is included at the end of the page's content. The JavaScript searches for the unique pixel on the page to tag the data it collects with the unique ID of the content, and also uses the position of the pixel to identify where the content ends so that visitor scroll depth can be measured.

How do I know if the tracking pixel is working?

If the tracker is working, it will show a 200 status. To find this, go to your article page on your website (it must be published through the CMP), right click your mouse and inspect the page in developer mode. It will look similar to the following image.


After opening the developer's tool, reload the page by pressing F5. As you can see in the image above, open the Network tab and search for pixel. If you see 200 in the Status column, then the tracking code is working correctly. If you want more details, search for tracker and click on it.