> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datalyr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing Tags

> Create, configure, and manage container tags from your dashboard

Manage all your tracking pixels, custom scripts, and third-party tags from the DATALYR dashboard without touching code.

## Accessing Tag Management

1. Go to **Dashboard → Settings → Pixels & scripts**
2. View all active and inactive tags
3. Click **Add New Tag** to create a tag

Tags load through the `dl.js` tracking tag you've already installed — there's no separate container script to add.

## Tag Types

### Inline Script

Execute custom JavaScript code directly on your pages.

**Use Cases:**

* Track button clicks
* Monitor form submissions
* Custom event tracking
* DOM manipulation
* Analytics events

**Example:**

```javascript theme={null}
// Track newsletter signup
document.querySelector('#newsletter-form').addEventListener('submit', function() {
  datalyr.track('newsletter_signup', {
    location: 'footer',
    page: window.location.pathname
  });
});
```

### External Script

Load external JavaScript files from third-party services.

**Use Cases:**

* Analytics platforms
* Chat widgets
* Heatmap tools
* A/B testing scripts
* Third-party integrations

**Example:**

```
https://cdn.example.com/analytics.js
```

### Tracking Pixel

Fire tracking pixels (image requests) for conversion tracking.

**Use Cases:**

* Conversion tracking
* Retargeting pixels
* Affiliate tracking
* Custom pixel endpoints

**Example:**

```
https://track.example.com/pixel?event=purchase&value=99.99
```

## Creating a Tag

### Step 1: Basic Information

**Tag Name**
Give your tag a descriptive name (e.g., "Meta Pixel - Homepage", "Chat Widget", "Scroll Tracker").

**Tag Type**
Choose from Inline Script, External Script, or Tracking Pixel.

**Status**
Set to Active to enable immediately, or Inactive to save as draft.

### Step 2: Configure Content

**For Inline Scripts:**
Write your JavaScript code in the code editor. Use built-in variables for dynamic values.

**For External Scripts:**
Enter the full URL to the external JavaScript file (must start with `https://`).

**For Tracking Pixels:**
Enter the pixel URL with any query parameters for conversion data.

### Step 3: Set Triggers

Choose when your tag fires:

**Page Load**
Fire when the page first loads (before DOM is ready).

**DOM Ready**
Fire when the DOM is fully loaded (recommended for most tags).

**History Change**
Fire when navigation changes in SPAs (React, Vue, Next.js).

**Scroll**
Fire when user scrolls past 100px down the page.

**Visibility Change**
Fire when browser tab becomes visible after being hidden.

### Step 4: Set Firing Frequency

Control how often the tag executes:

**Always**
Fire every time the trigger occurs. Use for analytics and tracking.

**Once per Page**
Fire only once per page load. Use for pixels and one-time scripts.

**Once per Session**
Fire once per browser session (survives across pages). Use for session-level tracking.

### Step 5: Add Conditions (Optional)

Add conditions to control when the tag fires:

#### URL Path Conditions

Match specific pages or patterns:

**Equals**

```
/checkout
```

Fires only on exact path.

**Contains**

```
/product
```

Fires on any path containing "/product".

**Starts With**

```
/blog/
```

Fires on all blog posts.

**Ends With**

```
/thank-you
```

Fires on thank you pages.

**Regex**

```
^/product/[0-9]+$
```

Advanced pattern matching.

#### Query Parameter Conditions

Check for specific parameters:

**Exists**

```
utm_source
```

Fires if parameter is present.

**Equals**

```
utm_source = facebook
```

Fires if parameter matches value.

**Contains**

```
utm_campaign contains summer
```

Fires if parameter contains substring.

#### Referrer Conditions

Target traffic from specific sources:

**Contains**

```
google.com
```

Fires for Google traffic.

**Empty**
Fires for direct traffic (no referrer).

**Not Empty**
Fires for any referred traffic.

#### Device Conditions

Target specific device types:

**Mobile**
Fires on mobile devices only.

**Tablet**
Fires on tablets only.

**Desktop**
Fires on desktop only.

#### Custom JavaScript

Write custom logic:

```javascript theme={null}
// Fire only for logged-in users
return window.user && window.user.isLoggedIn === true;
```

Return `true` to fire the tag, `false` to block it.

### Step 6: Use Built-In Variables

Use dynamic variables in your tags:

**Page Variables:**

* `{{Page URL}}`: Full page URL
* `{{Page Path}}`: URL path only
* `{{Page Hostname}}`: Domain name
* `{{Page Title}}`: Document title
* `{{Referrer}}`: Referrer URL

**UTM Parameters:**

* `{{UTM Source}}`: utm\_source parameter
* `{{UTM Medium}}`: utm\_medium parameter
* `{{UTM Campaign}}`: utm\_campaign parameter
* `{{UTM Term}}`: utm\_term parameter
* `{{UTM Content}}`: utm\_content parameter

**Other:**

* `{{Query String}}`: Full query string
* `{{Fragment}}`: URL hash
* `{{User Agent}}`: Browser user agent
* `{{Timestamp}}`: Current ISO timestamp
* `{{Random Number}}`: Random number (0-1)
* `{{Screen Resolution}}`: Screen width x height
* `{{Viewport Size}}`: Viewport width x height
* `{{Language}}`: Browser language

**Example Usage:**

```javascript theme={null}
// Track page view with dynamic values
datalyr.track('page_view', {
  url: '{{Page URL}}',
  title: '{{Page Title}}',
  referrer: '{{Referrer}}',
  utm_source: '{{UTM Source}}',
  utm_campaign: '{{UTM Campaign}}'
});
```

**In Pixel URLs:**

```
https://track.example.com/pixel?url={{Page URL}}&ref={{Referrer}}&ts={{Timestamp}}
```

## Common Tag Examples

### Meta Pixel Conversion Tracking

**Type:** Inline Script
**Trigger:** DOM Ready
**Frequency:** Once per Page
**Conditions:** URL path equals `/thank-you`

```javascript theme={null}
// Fire Meta Pixel purchase event
if (window.fbq) {
  fbq('track', 'Purchase', {
    value: 99.99,
    currency: 'USD'
  });
}
```

### Button Click Tracking

**Type:** Inline Script
**Trigger:** DOM Ready
**Frequency:** Always

```javascript theme={null}
// Track CTA button clicks
document.querySelectorAll('.cta-button').forEach(function(btn) {
  btn.addEventListener('click', function() {
    datalyr.track('cta_clicked', {
      button_text: this.textContent,
      page: '{{Page Path}}',
      url: '{{Page URL}}'
    });
  });
});
```

### Exit Intent Popup

**Type:** Inline Script
**Trigger:** DOM Ready
**Frequency:** Once per Session
**Conditions:** Device equals Desktop

```javascript theme={null}
// Show exit intent popup
let triggered = false;
document.addEventListener('mouseout', function(e) {
  if (!triggered && e.clientY <= 0) {
    triggered = true;
    // Show your popup
    document.getElementById('exit-popup').style.display = 'block';
  }
});
```

### Scroll Depth Tracking

**Type:** Inline Script
**Trigger:** Scroll
**Frequency:** Once per Page

```javascript theme={null}
// Track when user scrolls past 50%
const scrollPercent = (window.scrollY / document.body.scrollHeight) * 100;
if (scrollPercent > 50) {
  datalyr.track('scroll_depth_50', {
    page: '{{Page Path}}'
  });
}
```

### SPA Page View Tracking

**Type:** Inline Script
**Trigger:** History Change
**Frequency:** Always

```javascript theme={null}
// Track SPA navigation
datalyr.track('page_view', {
  url: '{{Page URL}}',
  path: '{{Page Path}}',
  title: '{{Page Title}}'
});
```

### Conditional Chat Widget

**Type:** External Script
**Trigger:** DOM Ready
**Frequency:** Once per Page
**Conditions:** URL path starts with `/support/`

```
https://cdn.chatservice.com/widget.js
```

Loads chat widget only on support pages.

## Managing Existing Tags

### Edit a Tag

1. Find the tag in your Container list
2. Click **Edit**
3. Make changes
4. Click **Save**

Changes take effect immediately (within cache duration).

### Pause a Tag

1. Click the toggle next to the tag name
2. Tag changes to **Inactive**
3. Tag stops firing immediately

### Delete a Tag

1. Click **Delete** next to the tag
2. Confirm deletion
3. Tag is permanently removed

## Testing Tags

### Enable Debug Mode

Add `?datalyr_debug=true` to your URL to see console logs:

```
https://yoursite.com?datalyr_debug=true
```

Check console for:

* `[DATALYR Container] Script fired: Your Tag Name`
* Tag execution details
* Condition matching results

### Check Network Requests

1. Open DevTools → Network tab
2. Filter by your external script domain or pixel URL
3. Verify requests are being sent

### Test Conditions

Use debug mode to see why tags fire or don't fire:

```
[DATALYR Container] Checking conditions for: Your Tag
[DATALYR Container] Condition passed: URL path contains /product
[DATALYR Container] Script fired
```

## Tag Priority and Loading

Tags load and execute in order:

1. **page\_load** triggers fire first
2. **dom\_ready** triggers fire after DOM loads
3. **history\_change** triggers fire on SPA navigation
4. **scroll** and **visibility\_change** fire when triggered

Tags created first in the dashboard fire before tags created later.

## Best Practices

**Name tags clearly**
Use descriptive names: "Meta Pixel - Purchase Event" not "Pixel 1".

**Use appropriate triggers**
Most tags should use DOM Ready unless they need to fire earlier.

**Set firing frequency correctly**
Use Once per Page for conversion pixels to avoid duplicate fires.

**Test with conditions**
Start with a test page condition before rolling out site-wide.

**Limit active tags**
Keep under 50 active tags for best performance.

**Use built-in variables**
Avoid hardcoding values that change (URLs, campaigns, etc.).

**Monitor errors**
Check container errors: `window.DATALYR.container.getErrors()`

## Troubleshooting

**Tag not firing?**

Check:

* Tag is Active (not Inactive)
* Trigger matches current page state
* Conditions are met (test with debug mode)
* External script URL is valid (https\:// required)
* Ad blockers are disabled

**Tag firing multiple times?**

Set firing frequency to Once per Page or Once per Session.

**Variables not replacing?**

Ensure exact syntax: `{{Page URL}}` (case-sensitive, with spaces and double braces).

**Conditions not working?**

Enable debug mode to see condition evaluation:

```
[DATALYR Container] Condition failed: URL path equals /checkout
[DATALYR Container] Current path: /cart
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Container Installation" icon="download" href="/container/installation">
    Install container script
  </Card>

  <Card title="Container Overview" icon="info" href="/container/overview">
    Learn about Container features
  </Card>

  <Card title="Container vs Direct" icon="code-compare" href="/container/container-vs-direct">
    Compare installation methods
  </Card>

  <Card title="Integrations" icon="plug" href="/integrations/overview">
    Connect ad platforms
  </Card>
</CardGroup>

## Need Help?

Questions about managing tags? Check our [troubleshooting guide](/troubleshooting/tracking-not-working) or contact support.
