Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #849393

    valuecentric
    Participant

    Hello,

    My boss has provided me a Google AdWords Conversion tracking code that we want to use to track when people hit submit on our Contact Form 7 forms. The script is below:

    <!– Google Code for Demo form completed Conversion Page
    In your html page, add the snippet and call
    goog_report_conversion when someone clicks on the
    chosen link or button. –>
    <script type=”text/javascript”>
    /* <![CDATA[ */
    goog_snippet_vars = function() {
    var w = window;
    w.google_conversion_id = 958894055;
    w.google_conversion_label = “le4ZCM7A7WQQ55-eyQM”;
    w.google_remarketing_only = false;
    }
    // DO NOT CHANGE THE CODE BELOW.
    goog_report_conversion = function(url) {
    goog_snippet_vars();
    window.google_conversion_format = “3”;
    var opt = new Object();
    opt.onload_callback = function() {
    if (typeof(url) != ‘undefined’) {
    window.location = url;
    }
    }
    var conv_handler = window[‘google_trackConversion’];
    if (typeof(conv_handler) == ‘function’) {
    conv_handler(opt);
    }
    }
    /* ]]> */
    </script>
    <script type=”text/javascript”
    src=”//www.googleadservices.com/pagead/conversion_async.js”>
    </script>

    We found a tutorial and added this to the wp-header.php file:

    <script>
    function Tracking(){
    var img = document.createElement(“img”);
    var goalId = “958894055”; // Your Google Conversion ID
    var randomNum = new Date().getMilliseconds();
    var value = 0;
    var label = “le4ZCM7A7WQQ55-eyQM”; // Your Google Conversion Label
    var url = encodeURI(location.href);

    var trackUrl = “http://www.googleadservices.com/pagead/conversion/”+goalId+”/?random=”+randomNum+”&value=”+value+”&label=”+label+”&guid=ON&script=0&url=”+url;
    img.src = trackUrl;
    document.body.appendChild(img);
    }
    </script>

    and then added the following to Contact Forms under Additional Settings:

    on_sent_ok: “jQuery(String.fromCharCode(60)+’img/’+String.fromCharCode(62)).attr(‘height’,’1′).attr(‘width’,’1′).css(‘border-style’,’none’).attr(‘src’,’http://www.googleadservices.com/pagead/conversion/’+google_conversion_id+’/?value=’+google_conversion_value+String.fromCharCode(38)+’label=’+google_conversion_label+String.fromCharCode(38)+’guid=ON’+String.fromCharCode(38)+’script=0′).appendTo(‘body’);”

    However, it doesn’t seem to be working. Am I placing the script in the wrong area? I’m reading under threads that mention it has to be placed in the functions.php file.

    Any help would be greatly appreciated!

    #849438

    Darshana
    Moderator

    Hi there,

    Thanks for writing in! Please refer to the following example (https://community.theme.co/forums/topic/how-to-add-a-custom-external-javascript-tag/#post-110065).

    Hope that helps.

    #849448

    valuecentric
    Participant

    Ah, so in lieu of what I had above, I basically would want to do something like this?

    add_action( ‘wp_head’, ‘Tracking’ );

    function Tracking(){
    ?>
    <script type=”text/javascript”>
    var img = document.createElement(“img”);
    var goalId = “958894055”; // Your Google Conversion ID
    var randomNum = new Date().getMilliseconds();
    var value = 0;
    var label = “le4ZCM7A7WQQ55-eyQM”; // Your Google Conversion Label
    var url = encodeURI(location.href);

    var trackUrl = “http://www.googleadservices.com/pagead/conversion/”+goalId+”/?random=”+randomNum+”&value=”+value+”&label=”+label+”&guid=ON&script=0&url=”+url;
    img.src = trackUrl;
    document.body.appendChild(img);
    }
    </script>

    <?php
    }

    #849506

    Darshana
    Moderator

    Hi there,

    You can add that with the following naming conversion to be unique.

    
    add_action( 'wp_head', 'my_adwords_conversion_tracking' );
    
    function my_adwords_conversion_tracking(){
    ?>
    	<script type="text/javascript">
    		//Your Custom script here
    	</script>
    <?php
    }
    

    Hope that’s clear.