0

I have a magento remarketing tag but I can not configure it correctly. I have the following parameters:

var google_tag_params = {
ecomm_prodid: 'REPLACE_WITH_VALUE',
ecomm_pagetype: 'REPLACE_WITH_VALUE',
ecomm_totalvalue: 'REPLACE_WITH_VALUE',
dynx_itemid: 'REPLACE_WITH_VALUE',
dynx_itemid2: 'REPLACE_WITH_VALUE',
dynx_pagetype: 'REPLACE_WITH_VALUE',
dynx_totalvalue: 'REPLACE_WITH_VALUE',
};

This returns me the following errors:

Number field should not be quoted: 'ecomm_totalvalue'
Number field should not be quoted: 'dynx_totalvalue'

Code used:

(function(){
 try {
    url_atual = $j('#urlAtual').val();
    alert(url_atual);
  if(url_atual == "catalog"){
   var prodid, totalvalue;
   //page product/category
   totalvalue = $j('#valor_produto').val();
   prodid = $j('#id_produto').val();
   alert(totalvalue);
   alert(prodid);
   dataLayer.push({
    'event': 'fireRemarketingTag',
    google_tag_params: {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'product',
      ecomm_totalvalue: totalvalue
    }
   });
  }
  else if (url_atual == "ajax") {
   var prodid, totalvalue;
  //cart
   console.log('entrou carrinho');
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'cart',
      'ecomm_totalvalue': totalvalue
    }
   });
  }
  else if (url_atual == "cms") {
   var prodid, totalvalue;
   //other pages/cms
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'purchase',
      'ecomm_totalvalue': totalvalue
    }
   });
  }
  else {
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': { }
   });
  }
 }
 catch (err) {}
}) ();

I have already tried setting up data layers but with no success. And after a lot of searching too, I did not find anything that could help me do the same setup on magento. Thanks in advance.

3
  • Please show the snippet that you use to assign the data to ecomm_totalvalue and dynx_totalvalue as the error messages states that you have the passed values quoted (i.e. ecomm_totalvalue: '100.00' does not work, where else ecomm_totalvalue: 100.00 does). Commented Jan 13, 2018 at 12:14
  • 1
    @ChristophFarnleitner I updated the question with the code used. Commented Jan 13, 2018 at 12:27
  • You can try github.com/sreichel/magento-Anaraky-GDRT
    – sv3n
    Commented Jan 13, 2018 at 13:28

1 Answer 1

1

As another solution based on the discussion in the comments you may be want to place something like this in your Minicart template (app/design/frontend/[theme]/[theme]/template/checkout/cart/minicart/items.phtml).

Please note, that this snippet never really got optimized nor revised as it was a quick fix in a particular situation some long time ago.

<!-- REMARKETING -->
<?php $conversionId = "YOUR CONVERSION ID"; // place your conversion id here ?>
<?php 
    $routeName = Mage::app()->getRequest()->getRouteName(); 
    $identifier = Mage::getSingleton('cms/page')->getIdentifier();
    $productReg = Mage::registry('current_product');
    $categoryReg = Mage::registry('current_category');

    $ecomm_category = null;
    $ecomm_prodid = null;

    if(Mage::app()->getFrontController()->getAction()->getFullActionName() === 'checkout_onepage_success'):
        $ecomm_pagetype = 'purchase';
        $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
        $order = Mage::getModel('sales/order')->load($orderId);
        foreach ($order->getAllItems() as $item):
            $itemIds[] = "'".$item->getSku()."'";
        endforeach;
        $ecomm_prodid = "[".implode(",", $itemIds)."]";

    elseif($routeName == 'cms' && $identifier == 'home'):
        $ecomm_pagetype = 'home';
        $ecomm_prodid = null;

    elseif($routeName == 'checkout'):
        $ecomm_pagetype = 'cart';

        $itemIds = array();
        $quote = Mage::helper('checkout/cart')->getQuote();
        if($quote->getItemsCount()):
            foreach ($quote->getAllItems() as $item):
                $itemIds[] = "'".$item->getSku()."'";
            endforeach;
        $ecomm_prodid = "[".implode(",", $itemIds)."]";
        else:
            $ecomm_prodid = null;
        endif;

    elseif($routeName == 'catalogsearch'):
        $ecomm_pagetype = 'searchresults';
        $ecomm_prodid = null;

    elseif($routeName == 'catalog'):
        if($categoryReg):
            $ecomm_category = $categoryReg->getName();
        endif;
        if($productReg):
            $ecomm_pagetype = 'product';
            $ecomm_prodid = "'".$productReg->getSku()."'";
        else:
            $ecomm_pagetype = 'category';
            $ecomm_prodid = null;
        endif;

    else:
        $ecomm_pagetype = 'other';
        $ecomm_prodid = null;
    endif;


    if($ecomm_pagetype == 'purchase'):
        $ecomm_totalvalue = $order->getGrandTotal();
    elseif($ecomm_pagetype == 'cart'):
        $ecomm_totalvalue = Mage::helper('checkout/cart')->getQuote()->getGrandTotal();
        if($ecomm_totalvalue == null):
            $ecomm_totalvalue = 0;
        endif;
    elseif($ecomm_pagetype == 'product'):
        $ecomm_totalvalue = $productReg->getFinalPrice();
    else:
        $ecomm_totalvalue = null;
    endif;
?>

<script type="text/javascript">
    var google_tag_params = {
        ecomm_pagetype: <?php echo "'".$ecomm_pagetype."'"; ?>,
        <?php if($ecomm_prodid != null): ?>
            ecomm_prodid: <?php echo $ecomm_prodid; ?>,
        <?php endif; ?>
        <?php if($ecomm_category != null): ?>
            ecomm_category: <?php echo "'".$ecomm_category."'"; ?>,
        <?php endif; ?>
        <?php if($ecomm_totalvalue != null): ?>
            ecomm_totalvalue: <?php echo $ecomm_totalvalue; ?>,
        <?php endif; ?>
    };
</script>
<script type="text/javascript">
    /* <![CDATA[ */
    var google_conversion_id = <?php echo $conversionId; ?>;
    var google_custom_params = window.google_tag_params;
    var google_remarketing_only = true;
    /* ]]> */
</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/<?php echo $conversionId; ?>/?guid=ON&amp;script=0"/>
    </div>
</noscript>

Even if alert(totalvalue); for example would return 100 it most likey is still just a string rather than a number. You can check that by alert(typeof(totalvalue)); // expected result in this case is 'string'.

So you will have to convert that string to a number using something like totalvalue = Number($j('#valor_produto').val()); or 'ecomm_totalvalue': Number(totalvalue). If you now alert(typeof(totalvalue)); you should get prompted number.

So, for example:

(function(){
 try {
    url_atual = $j('#urlAtual').val();
    alert(url_atual);
  if(url_atual == "catalog"){
   var prodid, totalvalue;
   //page product/category
   totalvalue = Number($j('#valor_produto').val()); // forcing type "number" rather than default "string"
   prodid = $j('#id_produto').val();
   alert(totalvalue);
   alert(prodid);
   dataLayer.push({
    'event': 'fireRemarketingTag',
    google_tag_params: {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'product',
      'ecomm_totalvalue': totalvalue // added missing quotes
    }
   });
  }
  else if (url_atual == "ajax") {
   var prodid, totalvalue;
  //cart
   console.log('entrou carrinho');
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'cart',
      'ecomm_totalvalue': totalvalue
    }
   });
  }
  else if (url_atual == "cms") {
   var prodid, totalvalue;
   //other pages/cms
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': {
      'ecomm_prodid': prodid,
      'ecomm_pagetype': 'purchase',
      'ecomm_totalvalue': totalvalue
    }
   });
  }
  else {
   dataLayer.push({
    'event': 'fireRemarketingTag',
    'google_tag_params': { }
   });
  }
 }
 catch (err) {}
}) ();

For easy debugging:

One easy way to test google-snippet integrations is using the Tag Assistant (by Google) Google Chrome extension (Tag Assistant on chrome.google.com).

General tag type definitions for Google Remarketing:

Example for retailers (more types linked in the source):

Custom parameter    Sample values   Definition
--------------------------------------------------------------------------
ecomm_prodid*       1234            The product ID parameter allows your dynamic ads to show people the exact product they viewed on your website.
ecomm_pagetype**    home,           The page type parameter collects which pages people visited on your website.
                    searchresults, 
                    category,       To use automatically created lists, this value must be in English, even if your site is in a different language.
                    product, 
                    cart, purchase, 
                    other
ecomm_totalvalue**  49.99           The total product value parameter is the value of the product. On cart pages with multiple products, total product value is the sum of all items someone has selected.


*Required
**Recommended

Source: AdWords Help on support.google.com

15
  • But how would that look in code suits? Because that's what I'm having trouble with. And this error that I put in the question comes precisely from that extension of google chrome. Commented Jan 13, 2018 at 13:14
  • @MatheusPortela - added the snippet to this post. If it does not work try alerting the type of the var totalvalue (i.e. alert(typeof(totalvalue));) Commented Jan 13, 2018 at 13:26
  • It did not work, it still continues to give the error in chrome extension. Commented Jan 13, 2018 at 13:40
  • what's the content of google_tag_params? You can check that in that Chrome extension or when you inspect the source of the page. Commented Jan 13, 2018 at 13:49
  • Of the following contents: Number field should not be quoted: 'ecomm_totalvalue' and Number field should not be quoted: 'dynx_totalvalue' Commented Jan 13, 2018 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.