Data & Analytics

Tealium Functions: Pharma Use Case

Overview

Tealium Functions is a powerful serverless environment that enables organizations to build and run lightweight, real-time JavaScript functions within the Tealium Customer Data Hub.

These functions allow for in-the-moment event data manipulation, data augmentation, and outbound integrations—helping teams implement more sophisticated logic, faster than traditional platform configurations alone.

Functions are especially useful for organizations looking to:

  • Clean, enrich, or restructure data as it enters Tealium.
  • Send real-time data to third-party systems.
  • Apply custom transformations not supported natively in AudienceStream or EventStream.

This article provides an overview of Tealium Functions and showcases three real-world use cases tailored for the pharmaceutical industry.

Tealium Functions

Tealium Functions are written in ECMAScript 2020 (ES11) and run on a GraalVM-based environment directly within the Tealium platform. There are three core function types:

Function Type When It Executes Common Uses
Data Transformation After data is collected, before it is processed Flattening data, redacting PII, renaming or modifying variables
Event Function After an event is processed Enriching event data, sending real-time data to vendors
Visitor Function After a visitor is processed Augmenting visitor profiles, syncing with CRM or support tools

Each function is tied to a single trigger, and developers can test, monitor, and configure functions directly within the Tealium UI.

 

Use Case #1: Detect and Hash PII in Event Data for Compliant Activation

Goal: Identify and secure sensitive PII in inbound event data to support compliant activation across paid media platforms.

Challenge: In regulated industries like pharmaceuticals, inbound data may contain personally identifiable information (PII) that must be redacted, masked, or transformed before use in segmentation or outbound activation. While Tealium provides built-in mechanisms to handle known fields like email, dynamic or user-generated content may require automated PII detection.

Solution:

import flatten from 'tealium/util/flatten';
import { SHA256 } from 'crypto-es/lib/sha256.js';

const options = { delimiter: '_' };

transform(async (event) => {
  event.data.udo = flatten(event.data.udo, options);
  const udo = event.data.udo;

  if (udo.customer_email) {
    udo.customer_email = udo.customer_email.trim().toLowerCase();
  }

  const piiInput = JSON.stringify({ Text: JSON.stringify(udo), LanguageCode: 'en' });

  const response = await fetch("https://comprehend.us-east-1.amazonaws.com", {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-amz-json-1.1',
      'X-Amz-Target': 'Comprehend.DetectPiiEntities',
      'Authorization': 'Bearer YOUR_AWS_AUTH_TOKEN_HERE'
    },
    body: piiInput
  });

  const result = await response.json();

  if (result.Entities && Array.isArray(result.Entities)) {
    result.Entities.forEach(entity => {
      const piiField = Object.keys(udo).find(key =>
        udo[key] && udo[key].toLowerCase().includes(entity.Text.toLowerCase())
      );
      if (piiField) {
        udo[`${piiField}_sha256`] = SHA256(udo[piiField]).toString();
        delete udo[piiField];
      }
    });
  }

  if (udo.event) {
    delete Object.assign(udo, { ['tealium_event']: udo['event'] })['event'];
  }
});

Outcome: Any detected PII (e.g., name, phone number, email) is replaced with a hashed version, ensuring that downstream tools (e.g., Meta, Google, DSPs) only receive secure, anonymized identifiers. This use case supports privacy compliance (e.g., HIPAA, GDPR) while maintaining marketing effectiveness.

Applicable KPIs:

  • Reduction in data privacy risk
  • Increase in compliant addressable audience size

Use Case #2: HCP Engagement Alerts to Field Reps

Goal: Notify field reps when high-value healthcare professionals (HCPs) engage with key digital content.

Challenge: Commercial teams need timely alerts to follow up with HCPs engaging with branded or unbranded materials, but marketing systems often lack real-time outbound triggers.

Solution:

import { event } from 'tealium';

const isHCP = event.data.hcp_verified === true;
const engagementType = event.data.engagement_type;
const assetName = event.data.asset_title;

if (isHCP && engagementType === 'clinical_material_view') {
  const payload = {
    hcp_id: event.data.hcp_id,
    email: event.data.hcp_email,
    asset_title: assetName,
    timestamp: event.data.event_timestamp
  };

  fetch("https://crm.pharma-company.com/api/hcp-alert", {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload)
  });
}

Outcome: Field reps receive timely notifications that specific HCPs have engaged with high-priority materials – enabling more relevant and timely follow-up and improving sales effectiveness KPIs like “Next Best Action” engagement.

Applicable KPIs:

  • Increase in HCP follow-up within 24 hours
  • Higher CTRs on rep-triggered emails
  • Improved closed-loop marketing outcomes

Use Case #3: Patient Support Program (PSP) Eligibility Check and Profile Enrichment

Goal: Enrich patient profiles with PSP eligibility information at the moment of website registration.

Challenge: Eligibility for PSPs may depend on condition, insurance, or location. These lookups typically require API calls to backend systems and are not available in Tealium out of the box.

Solution:

import { visitor } from 'tealium';

const zip = visitor.data.zip_code;
const productId = visitor.data.product_interest;

fetch(`https://psp-api.pharma-company.com/eligibility?zip=${zip}&product=${productId}`)
  .then(response => response.json())
  .then(data => {
    visitor.data.psp_eligible = data.eligible;
    visitor.data.psp_offer_code = data.offer_code || null;
  })
  .catch(error => console.error('Eligibility check failed:', error));

Outcome: The visitor profile is enriched with eligibility status and offer codes, enabling real-time personalization, automated onboarding, or CRM handoff based on eligibility for support programs.

Applicable KPIs:

  • Increase in PSP enrollments via digital channels
  • Higher engagement and conversion rate on support program CTAs
  • Improved data quality for downstream patient journeys

Best Practices

  • Limit scope: Each function should perform a discrete task to stay within memory and time constraints.
  • Avoid external dependencies: Functions cannot use third-party libraries except approved platform-provided utilities like crypto-es.
  • Use flatten() wisely: Simplify nested payloads before processing.
  • Monitor performance: Use the Monitoring tab to track execution time, errors, and invocations.
  • Trigger functions strategically: Functions are triggered via custom rules; use consistent naming (e.g., tealium_event) for maintainability.

Summary

Tealium Functions provide pharmaceutical marketers and data teams with a flexible, compliant way to enrich data, personalize engagement, and connect to essential systems in real time. Whether you’re powering field rep alerts or supporting PSP enrollment, Functions reduce time to value and increase agility across the omnichannel journey.

For more detailed documentation, visit the Documentation pages on Functions or reach out to your Tealium representative to discuss specific use case implementations.

 

retro
Robert Anderson
Principle CDP Strategist

Want a CDP that works with your tech stack?

Talk to a CDP expert and see if Tealium is the right fit to help drive ROI for your business.

Get a Demo