TypeScript SDK for Google Ads API with React hooks support
npm install redai-google-ads-sdkMột SDK TypeScript hiện đại cho Google Ads API với hỗ trợ React hooks và TanStack Query.
- ✅ TypeScript First: Type safety hoàn toàn với IntelliSense
- ✅ React Hooks: Tích hợp sẵn với TanStack Query
- ✅ 3-Layer Architecture: API → Services → Hooks
- ✅ Authentication: OAuth2 và Service Account
- ✅ Error Handling: Retry logic và error recovery
- ✅ Caching: Intelligent caching với TanStack Query
- ✅ Tree Shaking: Chỉ import những gì cần thiết
``bash`
npm install redai-google-ads-sdkhoặc
yarn add redai-google-ads-sdkhoặc
pnpm add redai-google-ads-sdk
`bash`
npm install react @tanstack/react-query axios
``
src/
├── types/ # TypeScript definitions
├── constants/ # API constants và query keys
├── api/ # Raw API calls
├── services/ # Business logic layer
├── hooks/ # React hooks với TanStack Query
├── auth/ # Authentication utilities
├── utils/ # Helper functions
└── index.ts # Main exports
`typescript
import { GoogleAdsAuthProvider } from 'redai-google-ads-sdk';
const authConfig = {
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
developerToken: 'your-developer-token',
redirectUri: 'http://localhost:3000/auth/callback',
scopes: ['https://www.googleapis.com/auth/adwords'],
};
function App() {
return (
);
}
`
`typescript
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
return (
);
}
`
`typescript
import { useGoogleAdsAuth } from '@redai/google-ads-sdk';
function LoginComponent() {
const { login, logout, isAuthenticated, user } = useGoogleAdsAuth();
return (
Xin chào, {user?.email}
$3
`typescript
import { useCustomers, useCustomer } from '@redai/google-ads-sdk';function CustomerList() {
const { data: customers, isLoading, error } = useCustomers();
if (isLoading) return
Đang tải...;
if (error) return Lỗi: {error.message}; return (
{customers?.map(customer => (
{customer.descriptiveName} ({customer.id})
))}
);
}
`$3
`typescript
import { useCampaigns, useCreateCampaign } from '@redai/google-ads-sdk';function CampaignManager() {
const customerId = 'your-customer-id';
const { data: campaigns, isLoading } = useCampaigns(customerId);
const createCampaign = useCreateCampaign();
const handleCreateCampaign = async () => {
try {
await createCampaign.mutateAsync({
customerId,
operations: [{
create: {
name: 'Campaign mới',
advertisingChannelType: 'SEARCH',
status: 'PAUSED',
campaignBudget:
customers/${customerId}/campaignBudgets/123,
biddingStrategyType: 'MANUAL_CPC',
}
}]
});
} catch (error) {
console.error('Lỗi tạo campaign:', error);
}
}; return (
{campaigns?.map(campaign => (
{campaign.name}
Status: {campaign.status}
))}
);
}
`🔑 API Reference
$3
#### Authentication
-
useGoogleAdsAuth() - Authentication state và methods
- useAuthHeaders() - Get current auth headers#### Customers
-
useCustomers(params?) - Lấy danh sách customers
- useCustomer(customerId) - Lấy thông tin customer
- useCustomerHierarchy(customerId) - Lấy hierarchy tree#### Campaigns
-
useCampaigns(customerId, params?) - Lấy danh sách campaigns
- useCampaign(customerId, campaignId) - Lấy thông tin campaign
- useCreateCampaign() - Tạo campaign mới
- useUpdateCampaign() - Cập nhật campaign
- useDeleteCampaign() - Xóa campaign#### Ad Groups
-
useAdGroups(customerId, params?) - Lấy danh sách ad groups
- useAdGroup(customerId, adGroupId) - Lấy thông tin ad group
- useCreateAdGroup() - Tạo ad group mới
- useUpdateAdGroup() - Cập nhật ad group#### Reporting
-
useReport(customerId, query) - Chạy report query
- usePerformanceMetrics(customerId, params) - Lấy performance metrics🛠️ Development
`bash
Clone repository
git clone https://github.com/redai/google-ads-sdk.git
cd google-ads-sdkInstall dependencies
npm installStart development
npm run devRun tests
npm testBuild
npm run build
``MIT License - xem LICENSE để biết thêm chi tiết.
Chúng tôi hoan nghênh mọi đóng góp! Vui lòng đọc CONTRIBUTING.md để biết thêm chi tiết.
- 📧 Email: support@redai.com
- 🐛 Issues: GitHub Issues
- 📖 Documentation: Docs