Cloudflare + Google Cloud Storage Hosting
Learn how to host your avatar on your own domain using Google Cloud Storage and Cloudflare.
Overview
This tutorial will guide you through hosting your avatar embed on your own website using:
- Google Cloud Storage for static file hosting
- Cloudflare for DNS management and CDN
- Custom domain like
https://avatar.mywebsite.com
Prerequisites
- A Google Cloud Platform account
- A Cloudflare account
- A domain name managed by Cloudflare
- Your avatar embed code from oktalkto.me
Step 1: Create Google Cloud Storage Bucket
1.1 Access Google Cloud Console
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to Storage > Browser
1.2 Create a New Bucket
Critical: For static website hosting, the bucket name must match your domain name exactly.
- Click Create bucket
- Enter bucket details:
- Bucket name:
avatar.mywebsite.com
(must match your domain exactly) - Location type: Select Region for better performance
- Location: Choose closest to your users
- Storage class: Standard
- Bucket name:
- Under Access control:
- Uncheck Enforce public access prevention
- Select Fine-grained access control
- Click Create
1.3 Configure Bucket for Web Hosting
- Select your newly created bucket
- Go to Permissions tab
- Click Grant Access
- Add new principals:
- New principals:
allUsers
- Role: Storage Object Viewer
- New principals:
- Click Save
Step 2: Create Your Avatar Website
2.1 Create index.html File
Create a local file called index.html
with the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Avatar</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
font-family: 'Arial', sans-serif;
overflow: hidden;
}
.avatar-container {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
border: none;
background: transparent;
}
.loading {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #00ffff;
font-size: 18px;
z-index: 1000;
}
.loading::after {
content: '';
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid #00ffff;
border-radius: 50%;
border-top-color: transparent;
animation: spin 1s linear infinite;
margin-left: 10px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 768px) {
.avatar-container {
width: 100vw;
height: 100vh;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Loading Avatar...</div>
<!-- Replace YOUR_API_KEY and YOUR_PROFILE_ID with your actual values -->
<iframe
class="avatar-container"
src="https://oktalkto.me/embed.html?apiKey=YOUR_API_KEY&profileId=YOUR_PROFILE_ID"
frameborder="0"
allow="microphone; camera; autoplay; encrypted-media; fullscreen"
allowfullscreen
onload="document.getElementById('loading').style.display='none'">
</iframe>
<script>
// Optional: Add custom tracking or analytics
console.log('Avatar loaded successfully');
// Handle iframe communication (optional)
window.addEventListener('message', function(event) {
if (event.origin !== 'https://oktalkto.me') return;
// Handle messages from avatar if needed
console.log('Message from avatar:', event.data);
});
</script>
</body>
</html>
2.2 Customize Your Avatar
- Replace
YOUR_API_KEY
with your actual API key from your avatar platform - Replace
YOUR_PROFILE_ID
with your actual profile ID from your avatar settings - You can get these values from your avatar profile page
- Customize the styling, colors, and branding as needed
Step 3: Upload to Google Cloud Storage
3.1 Upload Files
- In Google Cloud Console, go to your bucket
- Click Upload files
- Select your
index.html
file - Click Upload
3.2 Set Object Permissions
- Click on the uploaded
index.html
file - Go to Permissions tab
- Click Grant Access
- Add new principals:
- New principals:
allUsers
- Role: Storage Object Viewer
- New principals:
- Click Save
3.3 Configure Main Page
- In your bucket, click Website configuration
- Set:
- Main page:
index.html
- 404 page:
index.html
(optional)
- Main page:
- Click Save
Step 4: Configure Cloudflare DNS
4.1 Add CNAME Record
- Log in to your Cloudflare dashboard
- Select your domain
- Go to DNS > Records
- Click Add record
- Configure:
- Type:
CNAME
- Name:
avatar
(for avatar.mywebsite.com) - Target:
c.storage.googleapis.com
- Proxy status: ✅ Proxied (orange cloud)
- Type:
- Click Save
4.2 Add Page Rule for GCS
- In Cloudflare, go to Rules > Page Rules
- Click Create Page Rule
- Configure:
- URL:
avatar.mywebsite.com/*
- Settings:
- Host Header Override:
storage.googleapis.com
- Resolve Override:
c.storage.googleapis.com
- Path:
/avatar.mywebsite.com/$1
- Host Header Override:
- URL:
- Click Save and Deploy
Step 5: Test Your Setup
5.1 Verify DNS Propagation
- Wait 5-10 minutes for DNS propagation
- Test your URL:
https://avatar.mywebsite.com
- You should see your avatar loading
5.2 Test Different Devices
- Desktop browsers
- Mobile devices
- Different network connections
Step 6: Advanced Configuration (Optional)
6.1 Custom Domain SSL
Cloudflare automatically provides SSL certificates for your custom domain.
6.2 Performance Optimization
Add these Cloudflare optimizations:
- Speed > Optimization
- Enable Auto Minify for HTML, CSS, JS
- Enable Brotli compression
- Enable Early Hints
6.3 Security Settings
- Security > Settings
- Set Security Level: Medium
- Enable Bot Fight Mode
- Configure Rate Limiting if needed
Troubleshooting
Common Issues
Avatar not loading:
- Check if your API key and profile ID are correct
- Verify CORS settings in avatar profile
- Ensure domain is whitelisted in your avatar platform
DNS not resolving:
- Wait up to 24 hours for full propagation
- Check Cloudflare DNS records
- Verify Page Rule configuration
Permission errors:
- Ensure bucket is publicly accessible
- Check object-level permissions
- Verify allUsers has Storage Object Viewer role
Getting Help
If you encounter issues:
- Check browser console for errors
- Test with different browsers
- Verify all configuration steps
- Contact support with specific error messages
Cost Considerations
- Google Cloud Storage: ~$0.02 per GB/month
- Cloudflare: Free tier sufficient for most use cases
- Domain: Varies by registrar
Next Steps
- Set up multiple avatars with different subdomains
- Implement custom analytics tracking
- Add authentication for private avatars
- Configure custom branding and styling