mirror of
https://github.com/Zippland/worth-buying.git
synced 2026-01-19 01:21:11 +08:00
在购买决策计算器中添加AdSense广告初始化和展示位,优化广告集成
This commit is contained in:
28
page.tsx
28
page.tsx
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useMemo } from 'react';
|
||||
import React, { useState, useMemo, useEffect } from 'react';
|
||||
import { Calculator, ShoppingCart, TrendingUp, Shield, Clock, Heart, AlertTriangle, Settings } from 'lucide-react';
|
||||
import DecisionChecks from './components/DecisionChecks';
|
||||
|
||||
@@ -133,6 +133,20 @@ const PurchaseDecisionCalculator = () => {
|
||||
|
||||
const advice = getDecisionAdvice(calculateScore);
|
||||
|
||||
// AdSense 广告初始化
|
||||
useEffect(() => {
|
||||
try {
|
||||
if (typeof window !== 'undefined') {
|
||||
const adsbygoogle = (window as any).adsbygoogle;
|
||||
if (adsbygoogle) {
|
||||
adsbygoogle.push({});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('AdSense error:', err);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 评分选项定义
|
||||
const scoreOptions = {
|
||||
A1: [
|
||||
@@ -485,6 +499,18 @@ const PurchaseDecisionCalculator = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* AdSense 广告位 */}
|
||||
<div className="my-8 flex justify-center">
|
||||
<ins
|
||||
className="adsbygoogle"
|
||||
style={{ display: 'block', textAlign: 'center' }}
|
||||
data-ad-layout="in-article"
|
||||
data-ad-format="fluid"
|
||||
data-ad-client="ca-pub-8196371508613271"
|
||||
data-ad-slot="1659127609"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid lg:grid-cols-3 gap-6">
|
||||
{/* 评分区域 */}
|
||||
<div className="lg:col-span-2 space-y-6">
|
||||
|
||||
Reference in New Issue
Block a user