source

우커머스 3 온라인 결제 거래 없는 주문에 대한 구글 분석

manysource 2023. 10. 27. 22:01

우커머스 3 온라인 결제 거래 없는 주문에 대한 구글 분석

구글 분석에 주문에 대한 정보를 추가하려고 합니다.그러나 통계에는 주문에 대한 정보의 수신이 나와 있지 않습니다.이 사이트는 온라인 결제를 사용하지 않습니다(아마도 그 이유가 이와 관련이 있을 것입니다).을 사용했습니다.

함수에 코드를 추가했습니다.내 테마 디렉토리에 있는 php.

add_action( 'woocommerce_thankyou', 'google_analytics_integration', 20 );
function google_analytics_integration(){
    ?>
    <script>
        ga('require', 'ecommerce');
        <?php

        // GET the WC_Order object instance from, the Order ID
        $order = wc_get_order( $order_id );

        $order_key = $order->get_order_key();

        $transaction_id = $order->get_transaction_id(); // Doesn't always exist

        $transaction_id = $order_id; // (Or the order key or the transaction ID if it exist)

        ?>
        ga('ecommerce:addTransaction', {
            'id':          '<?php echo $transaction_id; // To be checked ?>',
            'affiliation': '<?php echo 'UA-130000602-1'; // replace by yours ?>',
            'revenue':     '<?php echo $order->get_total(); ?>',
            'shipping':    '<?php echo $order->get_shipping_total(); ?>',
            'tax':         '<?php echo $order->get_total_tax(); ?>',
            'currency':    '<?php echo get_woocommerce_currency(); // Optional ?>'
        }); <?php

        // LOOP START: Iterate through order items
        foreach( $order->get_items() as $item_id => $item ) :
        // Get an instance of the WC_Product object
        $product = $item->get_product();

        // Get the product categories for the product
        $categories = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) );
        $category = reset($categories); // Keep only the first product category
        ?>
        ga('ecommerce:addItem', {
            'id':       '<?php echo $transaction_id; ?>',
            'name':     '<?php echo $item->get_name(); ?>',
            'sku':      '<?php echo $product->get_sku(); ?>',
            'category': '<?php echo $category; ?>',
            'price':    '<?php echo wc_get_price_excluding_tax($product);  // OR wc_get_price_including_tax($product) ?>',
            'quantity': '<?php echo $item->get_quantity(); ?>',
            'currency': '<?php echo get_woocommerce_currency(); // Optional ?>'
        });
        <?php
        endforeach; // LOOP END
        ?>
        ga('ecommerce:send');
    </script>
    <?php
}

header.php에 카운터 코드를 추가했습니다.

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-130000602-1"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'UA-130000602-1');
</script>

내 계정 Google 분석 설정:

스크립트에서 확인된 충돌입니다.바닥이 사라집니다.

더미 데이터의 첫 번째 점검은 정상 작동 여부입니다.

  add_action('wp_head','add_gscript_trans');

        function add_gscript_trans(){?>

        <!-- Google Analytics -->
        <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

        ga('create', 'UA-130000602-1', 'auto');
        /* To load the ecommerce plugin, use the following command: */
        ga('require', 'ecommerce');
    /* You add transaction data to the shopping cart using the ecommerce:addTransaction command:*/

    ga('ecommerce:addTransaction', {
      'id': '1234',                     // Transaction ID. Required.
      'affiliation': 'Acme Clothing',   // Affiliation or store name.
      'revenue': '11.99',               // Grand Total.
      'shipping': '5',                  // Shipping.
      'tax': '1.29'                     // Tax.
    });

    /* Next, to add items to the shopping cart, you use the ecommerce:addItem command: */

    ga('ecommerce:addItem', {
      'id': '1234',                     // Transaction ID. Required.
      'name': 'Fluffy Pink Bunnies',    // Product name. Required.
      'sku': 'DD23444',                 // SKU/code.
      'category': 'Party Toys',         // Category or variation.
      'price': '11.99',                 // Unit price.
      'quantity': '1'                   // Quantity.
    });
   /* Finally, once you have configured all your ecommerce data in the shopping cart, you send the data to Google Analytics using the ecommerce:send command: */

   ga('ecommerce:send');

    </script>
    <!-- End Google Analytics -->
    <?php }

자세한 내용은 다음 링크를 참조하십시오: 전자 상거래 트랙

이 페이지가 도움이 될 수도 있습니다.

https://stackoverflow.com/a/54111464/7118098

또한 이전 줄이 보이지 않습니다.owl정의되어 있지만 jQuery에서 정의된 것처럼 보입니다.$()요소 ID에서.부엉이 Carousel()이 호출되기 전에 참조하는 요소에 실제로 연결되어 있는지 확인하십시오.부엉이 Carousel()이 호출되기 전에 부엉이 Carousel()이(가) 호출되기 전에 해당 부엉이 Carousel이 지연되지 않았는지 확인하십시오.

WooCommerce Google Analytics 통합 by WooCommerce 또는 Duracell을 사용해 보는 것은 어떨까요?토마스 가이거의 워드프레스를 위한 토미의 구글 태그 매니저

언급URL : https://stackoverflow.com/questions/54130384/google-analytics-integration-for-orders-without-online-payment-transaction-in-wo