0

I want to send a transaction-specific conversion value i.e: $totalValue

to google analytics alongside Google ad.

The current setup only sends the $totaValue info to google ads.

How can I send that info to google analytics as well?

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = id;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "sdvpCJaTwloQgs8YxgM";
var google_conversion_currency = "USD";

if (<? echo $totalValue ?>) {
        var google_conversion_value = <? 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="//www.googleadservices.com/pagead/conversion/id/?value=<? echo $totalValue ?>&amp;currency_code=USD&amp;label=sdvpCJaTwloQgs8YxgM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

Thanks to Michele I discovered the transaction method with google analytics but my PHP values aren't being parsed and prevent the rest of the code from loading.

ga('create', 'UA-xxxxxxxx-x', 'auto');
ga('send', 'pageview');

ga('require', 'ecommerce');

ga('ecommerce:addTransaction', {
  'id': '<?php echo $order; ?>',             
  'revenue': '<?php echo $transactionValue; ?>',           
});

ga('ecommerce:send');

enter image description here

Edwards
  • 107
  • 6

1 Answers1

1

You can use transaction and item hits: https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce.

Or an event with value.

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • Thank you for pointing me in the right direction. I tried using the transaction method below but my PHP value is not being parsed at the id property and prevents the rest of the code from running `ga('create', 'UA-xxxxxxxx-x', 'auto'); ga('send', 'pageview'); ga('require', 'ecommerce'); ga('ecommerce:addTransaction', { 'id': '', 'revenue': '', }); ga('ecommerce:send');` – Edwards Sep 24 '19 at 23:56
  • You're welcome. The problem could be an apostrophe problem or the value is empty or undefined or other related to php. However it does not depend on the JavaScript code of the transaction. – Michele Pisani Sep 25 '19 at 08:05
  • Working like a charm now. The first value I was passing in was empty. Thank you again, Michele!!! – Edwards Sep 25 '19 at 17:11