keatkeat

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
    }]
});

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-08-27
  • 2021-12-25
  • 2021-07-31
  • 2021-10-02
  • 2021-11-13
  • 2021-09-28
  • 2022-01-11
猜你喜欢
  • 2021-11-22
  • 2022-01-25
  • 2022-12-23
  • 2021-07-17
  • 2022-01-16
  • 2021-07-09
  • 2022-12-23
相关资源
相似解决方案