gtag 是用来取代之前的 ga 的
但其实它底层就是调用 ga 而已. 只是封装了一个上层.
1. start up script
<script async src="https://www.googletagmanager.com/gtag/js?id=@googleAnalyticsId"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag(\'js\', new Date()); gtag(\'config\', \'@googleAnalyticsId\', { cookie_domain: \'auto\', transport_type: \'beacon\', currency: \'MYR\', send_page_view: false }); gtag(\'event\', \'page_view\'); </script>
send_page_view 如果没有 set 的话,会自动发一次 page view 哦
2. custom event
call 就是 action
gtag(\'event\', \'call\', { event_category: \'engagement\', event_label: \'phone\' });
再比如
gtag(\'event\', \'location\', { event_category: \'engagement\', event_label: \'maps\' });
3. ecoomerce product list view
gtag(\'event\', \'view_item_list\', { items: [{ name: \'Product 1\', list_name: \'Category\', list_position: 1 }, { name: \'Product 2\', list_name: \'Category\', list_position: 2 }, ] });
4. product list CTR
gtag(\'event\', \'select_content\', { content_type: \'Product\', items: [{ name: el.textContent, list_name: \'Category\', list_position: index + 1, }] });
5. product detail view
gtag(\'event\', \'view_item\', {
items: [{
name: productName,
}]
});
6. add to cart
gtag(\'event\', \'add_to_cart\', { value: 100, items: [{ name: productName, price: 100, quantity: 1 }] });
remove from cart
gtag(\'event\', remove_from_cart, { value: 100, items: [{ name: productName, price: 100, quantity: 1 }] });
7. checkout
gtag(\'event\', \'begin_checkout\', { value: 100, checkout_step: 1, items: [{ name: \'Product 1\', price: 100, quantity: 1 }] });
next step
gtag(\'event\', \'checkout_progress\', { value: 100, checkout_step: 2, items: [{ name: \'Product 1\', price: 100, quantity: 1 }] });
next step
gtag(\'event\', \'checkout_progress\', { value: 100, checkout_step: 3, items: [{ name: \'Product 1\', price: 100, quantity: 1 }] });
8. purchase
gtag(\'event\', \'purchase\', { transaction_id: \'SO-001\', value: 100, shipping: 20, items: [{ name: \'Product 1\', price: 100, quantity: 1 }] });