Skip to content

Server-Side MarkTag Implementation

Complete implementation guide for server-side MarkTag - enterprise-grade tracking on merchant's custom domain.

Overview

Server-side MarkTag enables tracking on the merchant's own domain (e.g., mtag.merchantsite.com). This provides first-party cookies, better ad blocker resilience, and full domain control.

Best for:

  • Enterprise merchants requiring domain control
  • First-party cookie requirements
  • Maximum ad blocker resilience
  • Custom subdomain needs

Setup time: 10-40 minutes (DNS propagation)

Prerequisites

  • Partners API token (mp_live_...)
  • Merchant must have DNS access
  • Ability to add CNAME records
  • Access to merchant's website HTML

Complete Implementation Flow

Step 1: Create Merchant Account

Create a merchant account to associate with the MarkTag.

Request:

bash
curl -X POST https://api-alpha.markopolo.ai/v1/partners/merchant \
  -H "Authorization: Bearer mp_live_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Enterprise Store",
    "domain": "enterprisestore.com"
  }'

Response:

json
{
  "merchantId": "mch_9d8c7b6a-5e4d-3c2b-1a0f-9e8d7c6b5a4d",
  "name": "Enterprise Store",
  "domain": "enterprisestore.com",
  "createdAt": "2024-01-15T11:00:00Z"
}

Important: Save the merchantId for the next step.

Step 2: Generate Server-Side MarkTag

Generate a server-side MarkTag with the desired tracking domain.

Request:

bash
curl -X POST https://api-alpha.markopolo.ai/v1/partners/marktag/generate \
  -H "Authorization: Bearer mp_live_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "merchantId": "mch_9d8c7b6a-5e4d-3c2b-1a0f-9e8d7c6b5a4d",
    "type": "server-side",
    "domain": "enterprisestore.com"
  }'

Response:

json
{
  "tagId": "server-xyz789",
  "record": {
    "type": "CNAME",
    "name": "mtag-h7k9",
    "value": "mts1.markopolo.ai",
    "ttl": 300
  },
  "status": "inactive",
  "message": "New tag created successfully",
  "type": "server-side"
}

Key fields:

  • status: inactive - Waiting for DNS verification
  • record: Contains the CNAME details to configure
  • tagId: server-xyz789 - Will be used in tracking code

Step 3: Configure DNS

The merchant must add a CNAME record to their DNS settings.

DNS Configuration Details

From the API response, use the record field to configure DNS:

FieldValue
TypeCNAME
Namemtag
Valuemts1.markopolo.ai
TTL300

DNS Provider Instructions

Cloudflare
  1. Go to DNS management
  2. Click "Add record"
  3. Select Type: CNAME
  4. Name: mtag
  5. Target: mts1.markopolo.ai
  6. Important: Proxy status: DNS only (gray cloud)
  7. Save
GoDaddy
  1. Navigate to DNS Management
  2. Click "Add" in Records section
  3. Type: CNAME
  4. Host: mtag
  5. Points to: mts1.markopolo.ai
  6. TTL: 1 hour
  7. Save
AWS Route 53
  1. Go to Hosted zones
  2. Select the domain
  3. Click "Create record"
  4. Record name: mtag
  5. Record type: CNAME
  6. Value: mts1.markopolo.ai
  7. Create records
Namecheap
  1. Go to Advanced DNS
  2. Click "Add New Record"
  3. Type: CNAME Record
  4. Host: mtag
  5. Value: mts1.markopolo.ai
  6. TTL: Automatic
  7. Save

Step 4: Wait for DNS Propagation

DNS changes typically propagate within:

  • Best case: 5-10 minutes
  • Average: 15-30 minutes
  • Maximum: Up to 48 hours (rare)

Check DNS Propagation

bash
# Using dig
dig mtag-h7k9.enterprisestore.com CNAME +short

# Expected output:
# mts1.markopolo.ai.

# Using nslookup
nslookup mtag-h7k9.enterprisestore.com

# Using online tool
curl -L https://dnschecker.org/#CNAME/mtag-h7k9.enterprisestore.com

Step 5: Verify DNS Configuration via API

Once DNS is configured, verify it through the API.

Request:

bash
curl -X POST https://api-alpha.markopolo.ai/v1/partners/marktag/verify \
  -H "Authorization: Bearer mp_live_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "tagId": "server-xyz789",
    "subdomain": "mtag-h7k9.enterprisestore.com"
  }'

Response (422 - DNS Pending):

json
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "DNS verification pending. Please allow time for DNS propagation and try again",
    "statusCode": 422
  }
}

Response (200 - Verified):

json
{
  "verified": true
}

Step 6: Install the Tracking Script

Once DNS is verified (response: {"verified": true}), install the script on the website.

Extract TAG_ID and Domain

From the original MarkTag response:

  • tagId: server-xyz789
  • Tracking domain: mtag-h7k9.enterprisestore.com (using the generated subdomain from record.name)

The tracking implementation requires two script tags:

Installation Options

Option A: Direct HTML
html
<!DOCTYPE html>
<html>
  <head>
    <!-- Server-Side MarkTag Initialization -->
    <script>
      window.mtrem = window.mtrem || [];
      function mtag() {
        mtrem.push(arguments);
      }
      mtag(
        "init",
        "https://mtag-h7k9.enterprisestore.com?tagId=server-xyz789",
        {
          consent: true,
        },
      );
    </script>

    <!-- Server-Side MarkTag Loader -->
    <script async src="https://mtag-h7k9.enterprisestore.com/script"></script>

    <!-- Rest of your head content -->
    <title>Enterprise Store</title>
  </head>
  <body>
    <!-- Your website content -->
  </body>
</html>
Option B: Dynamic Installation
javascript
// For single-page applications
// Initialize tracking
window.mtrem = window.mtrem || [];
window.mtag = function () {
  window.mtrem.push(arguments);
};
window.mtag(
  "init",
  "https://mtag-h7k9.enterprisestore.com?tagId=server-xyz789",
  {
    consent: true,
  },
);

// Load the tracking script
const script = document.createElement("script");
script.src = "https://mtag-h7k9.enterprisestore.com/script";
script.async = true;
document.head.appendChild(script);

Step 7: Verify Tracking

Confirm events are being received.

Request:

bash
curl -X GET "https://api-alpha.markopolo.ai/v1/partners/events?merchantId=mch_9d8c7b6a-5e4d-3c2b-1a0f-9e8d7c6b5a4d&limit=5" \
  -H "Authorization: Bearer mp_live_YOUR_TOKEN"

Expected Response:

json
{
  "events": [
    {
      "eventId": "evt_789012",
      "type": "pageview",
      "url": "https://enterprisestore.com/",
      "timestamp": "2024-01-15T11:35:00Z",
      "domain": "mtag-h7k9.enterprisestore.com",
      "firstParty": true
    },
    {
      "eventId": "evt_789013",
      "type": "click",
      "url": "https://enterprisestore.com/products",
      "timestamp": "2024-01-15T11:35:30Z"
    }
  ],
  "pagination": {
    "currentPage": 1,
    "totalItems": 2
  }
}

Success! Events are now being tracked through the merchant's domain.

DNS Troubleshooting

Common Issues and Solutions

Issue: DNS Not Propagating

Symptoms: Verification keeps returning pending_dns

Diagnostic Steps:

bash
# Check if CNAME exists
dig mtag-h7k9.enterprisestore.com CNAME

# Check from Google's DNS
dig @8.8.8.8 mtag-h7k9.enterprisestore.com CNAME

# Check from Cloudflare's DNS
dig @1.1.1.1 mtag-h7k9.enterprisestore.com CNAME

Solutions:

  1. Verify CNAME record is saved in DNS provider

  2. Check for typos in hostname or target

  3. Ensure no conflicting A/AAAA records exist

  4. Wait additional time for propagation

  5. Clear local DNS cache:

    bash
    # macOS
    sudo dscacheutil -flushcache
    
    # Linux
    sudo systemd-resolve --flush-caches
    
    # Windows
    ipconfig /flushdns

Issue: Cloudflare Orange Cloud Enabled

Symptoms: CNAME points to Cloudflare proxy instead of tracking.markopolo.ai

Solution:

  1. Go to Cloudflare DNS settings
  2. Find the CNAME record
  3. Click the orange cloud icon to turn it gray (DNS only)
  4. Wait 5 minutes and verify again

Issue: Conflicting Records

Symptoms: Cannot add CNAME, error about existing records

Solution:

  1. Check for existing A or AAAA records for the same subdomain
  2. Remove conflicting records
  3. Add CNAME record
  4. Example check:
    bash
    dig mtag-h7k9.enterprisestore.com ANY

Issue: SSL Certificate Errors

Symptoms: HTTPS errors when loading the tracking script

Diagnostic:

bash
curl -I https://mtag-h7k9.enterprisestore.com/health

Solution:

  1. Ensure CNAME is correctly pointing to tracking.markopolo.ai
  2. SSL certificates are automatically provisioned after verification
  3. May take 5-10 minutes after DNS verification

Important DNS Notes

Subdomain Generation:

  • The API automatically generates a unique subdomain (e.g., mtag-h7k9)
  • You cannot choose your own subdomain
  • Each marktag gets its own unique subdomain identifier
  • The subdomain format is always mtag-xxxx where xxxx is a 4-character code
  • For multiple environments (staging, production), generate separate marktags - each will get its own unique subdomain

Migration from Client-Side

If migrating from client-side to server-side MarkTag:

Step 1: Setup Server-Side in Parallel

  1. Keep client-side MarkTag active
  2. Generate server-side MarkTag
  3. Configure DNS
  4. Wait for verification

Step 2: Install Both Scripts Temporarily

html
<!-- Temporary: both tracking implementations during migration -->

<!-- Client-Side MarkTag -->
<script>
  window.mtrem = window.mtrem || [];
  function mtag() {
    mtrem.push(arguments);
  }
  mtag("init", "https://mtag.markopolo.ai?tagId=client-abc123", {
    consent: true,
  });
</script>
<script async src="https://mtag.markopolo.ai/script"></script>

<!-- Server-Side MarkTag -->
<script>
  // Note: Using same mtrem/mtag is fine, both will be processed
  mtag("init", "https://mtag-h7k9.enterprisestore.com?tagId=server-xyz789", {
    consent: true,
  });
</script>
<script async src="https://mtag-h7k9.enterprisestore.com/script"></script>

Step 3: Verify Server-Side is Working

bash
# Check events from server-side domain
curl -X GET "https://api-alpha.markopolo.ai/v1/partners/events?tagId=server-xyz789" \
  -H "Authorization: Bearer mp_live_YOUR_TOKEN"

Step 4: Remove Client-Side

Once confirmed, remove the client-side scripts:

html
<!-- Only server-side now -->
<script>
  window.mtrem = window.mtrem || [];
  function mtag() {
    mtrem.push(arguments);
  }
  mtag("init", "https://mtag-h7k9.enterprisestore.com?tagId=server-xyz789", {
    consent: true,
  });
</script>
<script async src="https://mtag-h7k9.enterprisestore.com/script"></script>

Best Practices

  1. Subdomain Configuration - Use the exact subdomain provided by the API response (e.g., mtag-h7k9)
  2. TTL Settings - Start with lower TTL (300-3600) during setup, increase later
  3. DNS Monitoring - Set up monitoring for CNAME record
  4. SSL Verification - Always verify HTTPS is working before installing script
  5. Parallel Testing - Run alongside existing tracking tools during initial setup
  6. Documentation - Document the DNS configuration for merchant's records

API Reference

Generate Server-Side MarkTag

POST /v1/partners/marktag

Request Body:

json
{
  "merchantId": "string",
  "type": "server_side",
  "domain": "string"
}

Response:

json
{
  "tagId": "string",
  "record": {
    "type": "CNAME",
    "name": "mtag-h7k9",
    "value": "mts1.markopolo.ai",
    "ttl": 300
  },
  "status": "inactive",
  "message": "New tag created successfully",
  "type": "server-side"
}

Verify DNS Configuration

POST /v1/partners/marktag/verify

Request Body:

json
{
  "tagId": "string",
  "subdomain": "string"
}

Response (200 - Success):

json
{
  "verified": true
}

Next Steps