Google Conversion Script? Possible?

Adam

Member
Hey guys,

I am setting up my conversion script for Google Adwords and am trying to figure out where to put it and how to switch out the set conversion value with a dynamic one form my store.

Anyone done this before in AliDropship?

Here is the code:

PHP:
<!-- Google Code for Conversion Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = xxxxxxxxx;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "xxxxxxxxxxxxxxxx";
var google_conversion_value = 1.00;
var google_conversion_currency = "AUD";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/xxxxxxxx/?value=1.00&amp;currency_code=AUD&amp;label=xxxxxxxxxxxxxx&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

I want to swap out var google_conversion_value = 1.00; with instead the value of the sale.

If anyone can point me in the right direction that would be great. I do have some coding experience so feel free to talk in that language ;)

Cheers
Adam
 

Direct Webstore

Well-Known Member
WP Admin ... Customization / Checkout / Conversion tracking script:

is where it goes. As for your other questions ... no idea. :)
 

Adam

Member
Ok I'm either going blind, or the Davinci theme doesn't have that option in that settings area (was the first place I looked). Are you seeing it on the davinci theme?
 

Adam

Member
Ah now I see it thanks! Question though, does this change the price value dynamically as is suggested when implementing a conversion script into the store? The default script will have a fixed value, how would I ensure the price is the real value of the product?
 

Adam

Member
@Yaros or anyone else, any idea how to bring in the price dynamically rather than a fixed value (which is of course not accurate when you have multiple products)?
 

Yaros

Moderator
Staff member
We have never used it but we are planning to implement Adwords conversion tracking module (like for Facebook) asap.
 
I hope this help. this is a little something i have been cobbling together. its a little naughty. might not be the best way, but its been working pretty well. when i get more time to finish and clean up it could be better.

i put this code in the separate file then call it from the footer to load in.
like this:
<?php include 'google_scht.php'; ?>

near the end, replace INSERT_TRACKING_ID with your appropriate numbers from google.
Oh and this for woocommerce alidswoo. but maybe you can get some ideas from it.

Code:
<?php

//if (is_woocommerce() || is_cart() || is_checkout() || $_SERVER['REQUEST_URI'] == '/' ) :

        $cate = get_queried_object();
        $cateID = $cate->term_id;
               
        $argsH = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 1,
            'posts_per_page'        => '-1',
            'meta_query'            => array(
                array(
                    'key'           => '_visibility',
                    'value'         => array('catalog', 'visible'),
                    'compare'       => 'IN'
                )
            )
        );
        $argsC = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 1,
            'posts_per_page'        => '-1',
            'meta_query'            => array(
                array(
                    'key'           => '_visibility',
                    'value'         => array('catalog', 'visible'),
                    'compare'       => 'IN'
                )
            ),
            'tax_query'             => array(
                array(
                    'taxonomy'      => 'product_cat',
                    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
                    'terms'         => $cateID,
                    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                )
            )
        );
        $argsT = array(
            'post_type'             => 'product',
            'post_status'           => 'publish',
            'ignore_sticky_posts'   => 1,
            'posts_per_page'        => '-1',
            'meta_query'            => array(
                array(
                    'key'           => '_visibility',
                    'value'         => array('catalog', 'visible'),
                    'compare'       => 'IN'
                )
            ),
            'tax_query'             => array(
                array(
                    'taxonomy'      => 'product_tag',
                    'field' => 'term_id', //This is optional, as it defaults to 'term_id'
                    'terms'         => $cateID,
                    'operator'      => 'IN' // Possible values are 'IN', 'NOT IN', 'AND'.
                )
            )
        );
       
    if (is_product_category() ) {
                $qloop = new WP_Query($argsC);
                    while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
                        $prod_idz[] = $qloop->post->ID;
                        $rezultz = implode( $prod_idz, ', ');
                endwhile;
                wp_reset_query();
                //echo $rezultz;
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'category';
        //analytics retails code
            $prod_id_anl = $rezultz;
    } else
    if ( is_product_tag() ) {
                $qloop = new WP_Query($argsT);
                    while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
                        $prod_idz[] = $qloop->post->ID;
                        $rezultz = implode( $prod_idz, ', ');
                endwhile;
                wp_reset_query();
                //echo $rezultz;
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'category';
        //analytics retails code
            $prod_id_anl = $rezultz;
           
    } else
    if (is_product()) {
        global $product;
//    $custom_price_string = get_post_meta( $product->id, '_custom_composite_price_html', true );
    //    $custom_price_string = str_replace('$','',$custom_price_string);
        $_productz = wc_get_product( $product->id );
            $prod_id = 'ecomm_prodid:'.get_the_ID().',';
        //        if ($custom_price_string !=='') {
        //            $prod_price = 'ecomm_totalvalue: '.$custom_price_string;
        //        } else {
                    $prod_price = 'ecomm_totalvalue:'.$_productz->get_price();
        //        }
            $pagetype = 'product';
           
                       
            //analytics retails code
            $prod_id_anl = get_the_ID();
            $prod_price_anl = $_productz->get_price();
           
    } else
    if (is_shop() || $_SERVER['REQUEST_URI'] == '/') {
        $qloop = new WP_Query($argsH);
                    while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
                        $prod_idz[] = $qloop->post->ID;
                        $rezultz = implode( $prod_idz, ', ');
                endwhile;
                wp_reset_query();
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'home';
        //analytics retails code
            $prod_id_anl = $rezultz;
           
    } else
   
     if (is_wc_endpoint_url( 'order-received' )) {
        global $totalValue;
        $order_id = $wp->query_vars['order-received'];
        $order = new WC_Order($order_id );
            $items = $order->get_items();
            foreach ( $items as $item ) {
               $product_id = $item['product_id'];
                $products[] = $product_id;
                $rezultz = implode( $products, ', ');
                 
            }
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'purchase';
        //$prod_price = $totalValue;
        $prod_price = 'ecomm_totalvalue:'.$totalValue;
        //analytics retails code
            $prod_id_anl = $rezultz;
            $prod_price_anl = $totalValue;
           
    } else
   
    if (is_cart() || is_checkout() ) {
        global $woocommerce;
            $items = $woocommerce->cart->get_cart();
            foreach($items as $item => $values) {
                    $_product = $values['data']->post;
                    $ordlist[] = $_product->ID;
                    $rezultz = implode( $ordlist, ', ');
            }
            global $subTotal;
       
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'cart';
        $prod_price = 'ecomm_totalvalue:'.$subTotal;
        //analytics retails code
            $prod_id_anl = $rezultz;
            $prod_price_anl = $subTotal;
   
           
        } else{
         $qloop = new WP_Query($argsH);
                    while ( $qloop->have_posts() ) : $qloop->the_post(); global $product;
                        $prod_idz[] = $qloop->post->ID;
                        $rezultz = implode( $prod_idz, ', ');
                endwhile;
                wp_reset_query();
        $prod_id = 'ecomm_prodid:['.$rezultz.'],';
        $pagetype = 'other';
        //analytics retails code
            $prod_id_anl = $rezultz;
    }
    ?>
<script type="text/javascript">
    var google_tag_params = {
        <?php
        echo $prod_id.PHP_EOL;
        echo 'ecomm_pagetype:\''.$pagetype.'\','.PHP_EOL;
        echo $prod_price.PHP_EOL;
         ?>
    };
</script>
<script type="text/javascript">
    /* <![CDATA[ */
    var google_conversion_id = INSERT_TRACKING_ID;
    var google_custom_params = window.google_tag_params;
    var google_remarketing_only = true;
    var google_conversion_format = 3;
    /* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/INSERT_TRACKING_ID/?guid=ON&amp;script=0"/> </div>
</noscript>
<?php //endif; ?>
<?php

if (is_wc_endpoint_url( 'order-received' )  ) :
global $totalValue;
?>
<script type="text/javascript">
        /* <![CDATA[ */
        var google_conversion_id = INSERT_TRACKING_ID;
        var google_conversion_language = "en";
        var google_conversion_format = "3";
        var google_conversion_color = "ffffff";
        var google_conversion_label = "INSERT_TRACKING_ID";
        var google_conversion_currency = "USD";
        var google_conversion_value = <?php echo $totalValue; ?>;
        var google_remarketing_only = false;
        /* ]]> */
        </script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
        </script>
<noscript>
<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/INSERT_TRACKING_ID/?value=<?php echo $totalValue ?>&amp;currency_code=USD&amp;label=INSERT_TRACKING_ID&amp;guid=ON&amp;script=0"/> </div>
</noscript>
<?php endif; ?>
 

Adam

Member
Thanks mate, not using the WooCommerce version, but as you say, perhaps I can extract the solution out of it. Will post if I do.
 

rahul patil

New Member
Anyone getting actual conversion value in google ads? I think still there is no way in alidropship store to get conversion value in Google ads tracking. Someone from support?
 
Im also stuck there, and it seems that there's no support for Alid original And if you want to code it by urself good luck...the files are encrypted.... I know now why its better to go for the woo version for my opinion. If you need some thing out of the supported thing, ur getting at ur own... With the woo version you have all the plugins for ur specific.
 
Last edited:
Top