Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hiển thị quảng cáo cố định
Ví dụ này hiển thị quảng cáo liên kết bằng cách sử dụng thư viện Thẻ nhà xuất bản của Google (GPT).
Tìm hiểu thêm về quảng cáo liên kết trong Trung tâm trợ giúp của Google Ad Manager.
Xem trước quảng cáo cố định cuối màn hình
Bạn có thể hiển thị quảng cáo cố định trên màn hình minh hoạ trên bất kỳ trang nào hiển thị quảng cáo bằng GPT bằng cách thêm #gamTopAnchorDemo hoặc #gamBottomAnchorDemo vào URL. Ví dụ: https://www.example.com/#gamTopAnchorDemo
Bạn có thể sử dụng chức năng này để xem trước quảng cáo cố định trên trang web của mình mà không cần thay đổi mã. Điều này đặc biệt hữu ích để nhanh chóng xác thực giao diện và hành vi của neo trên các thiết bị và trong các môi trường hoạt động khác nhau.
Lưu ý về cách sử dụng
Để đảm bảo trải nghiệm người dùng tối ưu, quảng cáo cố định chỉ được yêu cầu trên những trang hỗ trợ định dạng chính xác. Do đó, defineOutOfPageSlot() có thể trả về giá trị rỗng; bạn nên kiểm tra trường hợp này để đảm bảo không thực hiện bất kỳ công việc nào không cần thiết. Hiện tại, quảng cáo cố định được hỗ trợ nếu đáp ứng các điều kiện sau:
GPT đang chạy trong cửa sổ trên cùng.
Trên một trang được tối ưu hoá cho thiết bị di động, trong đó tính năng thu phóng ở trạng thái trung tính; điều này thường có nghĩa là nhà xuất bản có <meta name="viewport" content="width=device-width,
initial-scale=1"> hoặc tương tự trong <head> của trang.
Khung nhìn có hướng dọc với chiều rộng từ 320px đến 1000px.
Chỉ yêu cầu quảng cáo cố định cuối màn hình trên những trang/môi trường mà bạn muốn quảng cáo cố định cuối màn hình xuất hiện. Quảng cáo cố định đủ điều kiện để phân phát đến máy tính, máy tính bảng và thiết bị di động.
Quảng cáo cố định tạo vùng chứa quảng cáo riêng. Không giống như các loại quảng cáo khác, bạn không cần phải xác định <div> cho quảng cáo liên kết. Quảng cáo cố định sẽ tự động tạo và chèn vùng chứa riêng vào trang khi quảng cáo được lấp đầy. Các vùng chứa này có thể chồng chéo hoặc che khuất các phần tử khác bằng cách sử dụng vị trí tuyệt đối hoặc cố định, vì vậy, bạn nên tránh đặt các phần tử đó ở những khu vực mà neo sẽ xuất hiện.
Nếu sử dụng cấu trúc yêu cầu duy nhất (SRA) trên một trang có nhiều vị trí, đừng gọi display() cho đến khi div vị trí quảng cáo tĩnh được tạo. Như đã giải thích trong phần Các phương pháp hay nhất về quảng cáo, lệnh gọi đầu tiên tới display() yêu cầu mọi vùng quảng cáo được xác định trước điểm đó. Mặc dù vị trí quảng cáo cố định không yêu cầu <div> được xác định trước, nhưng vị trí quảng cáo tĩnh thì có. Việc gọi display() trước khi các phần tử này xuất hiện trên trang có thể làm các tín hiệu có chất lượng thấp hơn, làm giảm khả năng kiếm tiền. Do đó, bạn nên trì hoãn lệnh gọi ban đầu cho đến khi xác định được các vùng tĩnh.
Chỉ có thể làm mới quảng cáo cố định hiển thị. Khi vùng quảng cáo liên kết được thu gọn hoặc chưa cuộn vào chế độ xem, tất cả lệnh gọi đến refresh() sẽ bị bỏ qua. Tuy nhiên, nếu bạn đang sử dụng disableInitialLoad() để kiểm soát việc tải và làm mới quảng cáo theo cách thủ công, thì lệnh gọi đầu tiên đến refresh() sẽ kích hoạt một yêu cầu quảng cáo bất kể chế độ hiển thị của vị trí.
[null,null,[],[],[],null,["# Display an anchor ad\n====================\n\nThis example displays an anchor ad using the Google Publisher Tag (GPT) library.\nLearn more about anchor ads in the\n[Google Ad Manager help center](//support.google.com/admanager/answer/10452255).\n\nPreview anchor ads\n------------------\n\nYou can display a demo anchor ad on any page that shows ads with GPT by adding\n`#gamTopAnchorDemo` or `#gamBottomAnchorDemo` to the URL. For example,\n`https://www.example.com/#gamTopAnchorDemo`.\n\nThis functionality can be used to preview anchor ads on your site with no code\nchanges required. This is especially useful to quickly validate how anchors will\nlook and behave on different devices and in different operating environments.\n\nUsage notes\n-----------\n\n- **To ensure an optimal user experience, anchor ads are only requested on\n pages that properly support the format.** Because of this,\n `defineOutOfPageSlot()` may return null; you should check for this case to\n ensure you're not doing any unnecessary work. Currently, anchor ads are\n supported if the following conditions are met:\n\n - GPT is running in the top window.\n - On a mobile optimized page where zoom is neutral; typically this means the publisher has `\u003cmeta name=\"viewport\" content=\"width=device-width,\n initial-scale=1\"\u003e` or similar in the `\u003chead\u003e` of the page.\n - Viewport is in a portrait orientation with a width between `320px` and `1000px`.\n- **Only request anchor ads on pages/environments where you want an anchor to\n appear.** Anchor ads are eligible to serve to desktop, tablet, and mobile\n devices.\n\n | **Note:** You can use Chrome DevTools [mobile simulation](//developers.google.com/web/tools/chrome-devtools/device-mode#viewport) to test anchor ads on mobile from a desktop environment.\n- **Anchor ads generate their own ad container.** Unlike other ad types, it's\n not necessary to define a `\u003cdiv\u003e` for anchor ads. Anchor ads automatically\n create and insert their own container into the page when an ad fills. These\n containers may overlap or occlude other elements using absolute or fixed\n positioning, so it's recommended to avoid placing such elements in areas\n where anchors are meant to appear.\n\n- **If using single-request architecture (SRA) on a page with multiple slots,\n don't call `display()` until static ad slots divs are created.** As\n explained in [Ad Best Practices](//developers.google.com/publisher-tag/guides/ad-best-practices#use_single_request_architecture_correctly), the first call to `display()`\n requests every ad slot defined prior to that point. Although anchor ad slots\n do not require a predefined `\u003cdiv\u003e`, static ad slots do. Calling `display()`\n before these elements are present on the page can result in lower quality\n signals, reducing monetization. Because of this, we recommend delaying the\n initial call until after the static slots are defined.\n\n- **Only visible anchor ads may be refreshed.** When an anchor ad slot is\n collapsed or not yet scrolled into view, all calls to `refresh()` are\n ignored. If you're using `googletag.setConfig({ disableInitialLoad: true })`\n to manually [control ad loading and refresh](//developers.google.com/publisher-tag/guides/control-ad-loading), however, the\n first call to `refresh()` will trigger an ad request regardless of the slot\n visibility.\n\nSample implementation\n---------------------\n\n[View demo](https://googleads.github.io/google-publisher-tag-samples/display-anchor-ad/js/demo.html) This sample makes use of library features that are not fully supported when running in an iframe. To view a demo of this sample in a new window, click the **View demo** button above. \n\n### JavaScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-anchor-ad/js) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-anchor-ad/js)\n\n### TypeScript\n\nLoading...\n----------\n\nLoading...\n----------\n\n[Improve this sample](https://github.com/googleads/google-publisher-tag-samples/tree/main/dist/display-anchor-ad/ts) [Report an issue](https://github.com/googleads/google-publisher-tag-samples/issues/new?labels=documentation&template=sample-feedback.md&title=Sample+feedback%3A+display-anchor-ad/ts)"]]