Manual initialization
Overview
Manual initialization gives you full control over SDK configuration using Hood('init', tag, config) with complex object configurations.
Basic setup
<script>
window.HoodEngage = window.HoodEngage || [];
function Hood() { HoodEngage.push(arguments); }
Hood('init', 'NjY4bL60M84D7DQ235QxNDY4MjE0NhGg', {
// Your configuration here
});
</script>
<script src="https://sdk.ocmcore.com/sdk/ht-latest.js"></script>
Configuration options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
analytics | boolean | No | false | Enable/disable analytics tracking (page views, clicks) |
crashlytics | boolean | No | false | Enable/disable JavaScript error reporting |
consent | object | No | { enabled: false } | Consent settings for GDPR compliance |
push_config | object | No | {} | Push notification configuration (VAPID keys, SW settings) |
modals_config | object | No | {} | Modal configurations (templates, triggers, filters, A/B tests) |
tag_config | object | No | {} | Custom tag configurations for event tracking |
modal_url | string | No | https://cdn.ocmtag.com/c/ | Base URL for modal templates |
tag_url | string | No | https://cdn.ocmtag.com/c/ | Base URL for auto-conf JSON |
Quick example
Basic manual initialization with core settings:
Hood('init', 'TAG_ID', {
analytics: true, // Enable analytics
crashlytics: true, // Enable error reporting
consent: { enabled: true } // Consent settings
});
More examples
For comprehensive examples including push notifications, modals, A/B testing, and advanced configurations, see Manual configuration examples.
Advanced configuration options
Guaranteed execution with HoodOnLoad
If you need to ensure your configuration is applied after the script loads, use the HoodOnLoad function:
<script>
function HoodOnLoad() {
Hood('init', 'TAG_ID', {
analytics: true,
modals_config: { /* your config */ }
});
}
</script>
<script onload="HoodOnLoad()" data-disable-autoconf="1" src="https://sdk.ocmcore.com/sdk/ht-latest.js"></script>
Alternative: Direct execution after load
For maximum control, you can also execute configuration directly after the script loads:
<script src="https://sdk.ocmcore.com/sdk/ht-latest.js"></script>
<script>
// Configuration executes after SDK is fully loaded
Hood('init', 'TAG_ID', {
analytics: true,
modals_config: { /* your config */ }
});
</script>
Why queue before script load?
The SDK uses a queue system (HoodEngage) to collect calls before the script loads. If the script loads before your configuration calls, it might:
- Execute with default settings
- Override your queued configuration
- Miss your custom settings entirely
The queue ensures your configuration is applied regardless of load timing.
When to use
| ✅ Good for | ❌ Not suitable for |
|---|---|
| Complex modal setups | Simple setups |
| A/B testing configurations | Quick integration |
| Advanced targeting rules | Basic tracking only |
| Custom push configurations | Standard configurations |
| Dynamic configurations | Non-technical teams |
| Full control over features | Limited development resources |
| Custom event tracking | Static websites |
| Multi-environment deployments | Single-page applications (basic) |
Best practices
Auto-conf behavior: When using Hood('init', tag, config) with config object, auto-conf is automatically disabled. Only use data-disable-autoconf="1" if you’re using Hood('init', tag) without config object but want to prevent auto-conf.
Queue calls: Always queue Hood() calls before script loads to prevent race conditions where the script might load and execute before your configuration is set.
Validate config: Test configurations in development first
Use templates: Store complex configs in variables for reusability