Episerver (Optimizely) Integrations Overview | OpsBlu Docs

Episerver (Optimizely) Integrations Overview

Complete guide to integrating analytics and marketing tools with Episerver CMS and Commerce (now Optimizely)

Episerver, now rebranded as Optimizely, is a powerful .NET-based content management and digital commerce platform. This guide covers integrating analytics and marketing tools with both Episerver CMS and Commerce products.

About Episerver/Optimizely

Note: Episerver rebranded to Optimizely in 2020, but many developers still refer to it as Episerver. This documentation uses both names interchangeably.

Platform Overview

  • Technology Stack: Built on .NET (ASP.NET Core for CMS 12+)
  • Products: Episerver CMS and Episerver Commerce
  • Architecture: Block and page type architecture with Razor view templates
  • Multi-tenancy: Built-in multi-site and multi-language support
  • Headless Options: Content Delivery API for headless implementations

Key Features for Analytics Integration

  1. Client Resources System: Centralized script and stylesheet management
  2. Razor Templates: Server-side rendering with .NET
  3. Content Types: Blocks, pages, and commerce-specific content
  4. Built-in Tracking: Episerver Tracking for analytics
  5. Optimizely Integration: Native integration with Optimizely Web Experimentation

Available Integration Guides

Google Analytics 4

Google Tag Manager

Meta Pixel

Integration Approaches

Add tracking code directly to Razor templates for maximum control and server-side data access.

Pros:

  • Access to server-side data (content properties, user info, commerce data)
  • Full control over rendering logic
  • Strong typing with C# models
  • Easy to maintain and version control

Example:

@model MyPageType

<script>
  // Access server-side data
  window.dataLayer = window.dataLayer || [];
  window.dataLayer.push({
    'pageType': '@Model.ContentType.Name',
    'pageId': '@Model.ContentLink.ID',
    'language': '@Model.Language.Name'
  });
</script>

2. Client Resources

Use Episerver's Client Resources system to register scripts globally or per-site.

Pros:

  • Centralized script management
  • Automatic versioning and bundling
  • Dependency management

Example:

[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ClientResourceInitialization : IInitializableModule
{
    public void Initialize(InitializationEngine context)
    {
        context.Locate.Advanced.GetInstance<IClientResourceService>()
            .RegisterScript("analytics", "/Scripts/analytics.js");
    }
}

3. Blocks for Tracking Scripts

Create reusable blocks for tracking code that editors can add to pages.

Pros:

  • Editor-friendly
  • Reusable across pages
  • Can be added to shared layouts

4. Initialization Modules

Use initialization modules to inject tracking code programmatically.

Pros:

  • Runs on application startup
  • Can add scripts conditionally
  • Integration with dependency injection

Best Practices

Performance Considerations

  1. Async Loading: Always load tracking scripts asynchronously
  2. Script Placement: Add scripts at the end of <body> when possible
  3. Bundling: Use Episerver's bundling for custom tracking scripts
  4. CDN: Leverage Episerver's CDN support for static resources

Content Delivery API (Headless)

For headless implementations:

  1. Return tracking data via API responses
  2. Implement tracking client-side in your frontend framework
  3. Use content properties to store tracking IDs
  4. Consider server-side tracking for sensitive data

Multi-site Support

When managing multiple sites:

  1. Use site-specific configuration files or database settings
  2. Access current site via ISiteDefinitionRepository
  3. Store tracking IDs as site-level settings
  4. Create reusable components that adapt to current site
var currentSite = _siteDefinitionRepository.Get(SiteDefinition.Current.Id);
var gaTrackingId = currentSite.GetProperty("GATrackingId")?.ToString();

Multi-language Support

  1. Track language in data layer: @Model.Language.Name
  2. Use content URLs that include language: @Url.ContentUrl(Model.ContentLink)
  3. Track language switches as events
  4. Consider language-specific views and conversion goals

Commerce-Specific Considerations

For Episerver Commerce implementations:

  1. Product Data: Access rich product information from catalog
  2. Cart Data: Track cart modifications and abandonments
  3. Order Data: Implement purchase tracking with full order details
  4. User Segments: Integrate customer segmentation data
  5. Promotions: Track promotion usage and effectiveness

Security and Privacy

GDPR Compliance

  1. Consent Management: Implement cookie consent before loading trackers
  2. Data Minimization: Only collect necessary data
  3. User Rights: Provide mechanisms for data deletion
  4. Privacy Policy: Link to privacy policy in tracking implementations

Content Security Policy (CSP)

If using CSP headers:

  1. Allow tracking domains in script-src
  2. Allow connection to analytics endpoints in connect-src
  3. Consider using nonces for inline scripts
  4. Test CSP rules in report-only mode first

Testing Your Integration

  1. Local Development: Test in CMS edit mode and preview mode
  2. Browser DevTools: Verify requests in Network tab
  3. Tag Assistants: Use Google Tag Assistant or Meta Pixel Helper
  4. Real-Time Reports: Monitor real-time analytics dashboards
  5. Multi-site Testing: Test each site configuration separately
  6. Language Testing: Verify tracking across all languages

Common Challenges

  1. Edit Mode vs. View Mode: Prevent tracking in edit mode
  2. Preview Mode: Decide whether to track preview traffic
  3. Scheduled Content: Handle content that's not yet published
  4. Personalization: Track personalized content variations
  5. A/B Testing: Integrate with Optimizely Web Experimentation

Support Resources

Next Steps

Choose an integration guide based on your analytics platform:

  1. Start with GTM Setup for flexible tag management
  2. Or go directly to GA4 Setup for Google Analytics
  3. Add Meta Pixel for Facebook advertising

For issues, see our Troubleshooting Guide.