Google adwords conversion tracking integration in joomla php file - php

I am trying to include a piece of code from Google Conversion Tracking into my business contact from which is based on Jomla. The code should be integrated once the Thank you message appears but unfortunately I am very unexperienced with javascript and php. Could someone please give me a hand having these two pieces of code combined?
Thank you very much, James
Code Jomla
//<![CDATA[
<!--
window.addEvent('load', function() {
changeCaptcha(".$this->profile->id.",0);\n".($use_ajax?"resetSubmit(".$this->profile->id.");\n":"")."
if($(typeof SqueezeBox!='undefined' && 'system-message')) {
SqueezeBox.initialize();
SqueezeBox.open($('system-message'), {
handler: 'adopt',
size: {x: $('system-message').offsetWidth+30, y: $('system-message').offsetHeight+30}
});
}
});
//-->
//]]>
Code Google:
<!-- Google Code for Contact Form Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1033530737;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "A8yvCJrs4AIQtHey6hT";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript"
src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="http://www.googleadservices.com/pagead/conversion/1033530737/? label=A8yvCJrs4AIQtHey6hT&guid=ON&script=0"/>
</div>
</noscript>

It has a joomla plugin that includes the conversion code on the default page of the contact: http://www.joomlaadwordsconversion.com/

Related

How create link in jQuery?

I have a jQuery notification. When I click on the notification it should go the intended page.
In PHP we can achieve that by doing following.
$link = 22;
echo "Click to read more";
How to achieve such in JQuery? I have notification pop up and link variable ready.
var link = "home.php?destination=22";
You can create HTML element using jQuery
var link = "home.php?destination=22";
//Create anchor element
var anchor = $('<a />', {
"href": link,
"text": "Click to read more"
})
//Append the element
$('#dialog').append(anchor).dialog();
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="dialog" title="Basic dialog">
</div>
you can achieve it using window.location.href in java script.
<button onclick="myFunction()">Click me to read more</button>
<script>
function myFunction() {
window.location.href = 'home.php?destination=22';
}
</script>

How to transfer JQuery variable into PHP variable in a modal window without page refresh

I am new to this client variable to server variable transfer process.
Essentially I have a Google maps api function and have a marker on a map to represent a username in a users table (MySQL) of my PHP web app. When I double click on that map marker my Jquery function is popping up a modal and I am able to get the username in an id/name element (chosenUser) in a . However, I now need to be able to access this value in a PHP variable ($chosenUser) without any "submit" or page refresh, so that I can invoke my PHP function - getUserChannelID($chosenUser), and continue with the rest of the logic.
My disconnect is the ability to be able to access that value coming through on the id/name as #chosenUser and transfer it to a PHP variable $chosenUser without a "submit" or page refresh. All the code below is on the same page.
I am reading about the use of AJAX to do this in SF posts but since I quite the infant with AJAX I am getting confused on how exactly this can be done on the same page without a form "submit" or page refresh.
Can you please help correcting the code below so that I can get that value in #chosenUser to the PHP variable $chosenUser?
Here's my code all in the same PHP file.
<?php
require_once("classes/autoload.php");
$db = new Database();
....
?>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/bootstrap.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js" ></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid" style="margin: 0 auto;">
<div style="height: 100%; position: relative; top:30px;">
<div id="map" style="height: 100%;"></div>
</div>
<div class="modal fade" id="showChannel" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Channel Preview</h4>
</div>
<div class="modal-body">
<div>
<input type="hidden" id="chosenUser" name="chosenUser" value="">
<!-- This is where I need help. How do I transfer that value I am getting for "chosenUser" above into the PHP variable $chosenUser - ideally the code in the next line would need to be executed -->
<?php $channelId = $db->getUserChannelID($chosenUser); ?>
.....
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.20&sensor=false"></script>
<script src="multiple_marker/oms.js"></script>
<script type="text/javascript">
var mapMarkers = [];
var infowindow = null;
var infowindowOpen;
var map, oms;
var gm = google.maps;
var markerIcons = new Array();
var gmarkers = [];
function getCoords() {
$.ajax({
url: "markers.php", // this markers.php provides the value of "Locations" array used below
type: "POST",
data: {
foo: "bar"
},
dataType: "json",
success: function (returnedData) {
console.log(returnedData);
if(!spiderify)
moveMarkerMap(returnedData);
//window.setInterval(getCoords, 10000);
window.setTimeout(getCoords, 2000);
}
});
}
function MarkerMap(json) {
var iconBase;
oms.addListener('click', function (marker) {
console.log('clicked');
});
if ((json.Locations.length > 0)) {
for (i = 0; i < json.Locations.length; i++) {
var location = json.Locations[i];
var username = location.username; // I am getting the value of username here
var myLatlng = new gm.LatLng(location.Lat, location.Long);
var marker = new gm.Marker({
position: myLatlng,
map: map,
username: username,
});
var infowindow = new gm.InfoWindow();
var div = document.createElement('DIV');
gm.event.addListener(marker, 'dblclick', (function (marker, div, infowindow) {
return function () {
$('#showChannel').modal('show');
$('#chosenUser').val(marker.username); //passing the value of marker.username to the modal input id/name="chosenUser"
};
})(marker, div, infowindow));
gmarkers[id] = marker;
}
}
window.map = map;
window.oms = omg;
}
gm.event.addDomListener(window, 'load', initialize);
</script>
Well, you can't exactly communicate between PHP and JS in the way you're thinking of. PHP is executed while the page is loading, before any content is displayed, before any javascript is even sent to the client, so it's impossible to do it as you wish.
What you can do is call a PHP script once the page is finished loading, using javascript. You can do this whenever you like, using a delay loop, when clicking a button, any way you can call your javascript function. That way you can send information from javascript to PHP, and when the PHP script finishes running it can report back information to javascript.
You want a variable from js in PHP, there are multiple ways of doing this, such as POST or GET requests. I'll post an example using POST, which is the same thing you'd use to send a form. You'll need to include jQuery for this to work.
JS
var myVar = "my info";
var myVar2 = "my other info";
$.post("myscript.php", {
info1: myVar,
info2: myVar2
}, function(answer) {
// answer will contain whatever the PHP script printed
// in this example answer will be "success"
alert(answer);
} );
PHP
$var1 = $_POST['info1'];
$var2 = $_POST['info2'];
if(!empty($var1) && !empty($var2))
{
echo "success";
}
It's up to you to implement it now.

Google conversions not registering within PHP page

Although relatively new to coding, I have successfully implemented a number of tracking codes before, but I am having serious problems getting one conversion code to register on my site.
Whilst I have put it into the relevant section of PHP in the code, and even done test conversions and seen it in the source, Google has failed to register a single conversion and the goal still shows up as 'Unverified'.
I have read various blogs and what Google has to say about implementing the code in PHP - most of which seem to disagree with one another. If anyone has any ideas, I would be hugely grateful as it is a key indicator to tracking my AdWords performance.
Below is the code that Google gives me to implement untouched:
<!-- Google Code for Almost there Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
var google_conversion_value = 0;
/* ]]> */
</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/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
Now the code the way Google wants you to edit it for PHP, detailed under the section here: https://support.google.com/adwords/answer/1722054?hl=en-GB
<!-- Google Code for Almost there Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
/* ]]> */
</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/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
I have wasted about 3 days on this on and off now and have spent long enough trying to click on adverts and creating fake accounts to test it with to get it to trigger.
As another safeguard I will post the relevant PHP section in it's entirety below too.
It's a part triggered to confirm a subscription payment may be useful to see you can never have too much information, diagnosing a problem.
<?php
/* Template Name: Subscription Confirmation */
if (isset($_POST['activate_subscription']) && isset($_POST['token'])) {
$activation = completeSubscription($_POST['token']);
//completeSubscription Handles everything here. If this even runs, it's all gone wrong.
$activate_failed = true;
} else if (isset($_GET['token']) && isset($_GET['PayerID'])) {
$transaction = getTransactionDetails($_GET['token']);
if ($transaction['ACK'] == "Success") $sub = updateSubscriptionDetails($transaction);
} else {
header("Location: /join/membership/");
exit();
}
get_header();
?>
<div class="row subhero">
<div class="twelve columns">
<?php if (!isset($activate_failed) && $transaction['ACK'] == "Success") { ?>
<h1>Almost there!</h1>
<p class="subheader">Thank you for configuring your subscription with PayPal.</p>
//***************** ANALYTICS CODE
<!-- Google Code for Subscription Conf Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
/* ]]> */
</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/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
//*********************END OF ANALYTICS CODE
</div>
</div>
</div> <!-- end container -->
<div class="buyticketarea">
<div class="row">
<div class="eight columns offset-by-two">
<p class="subheader">Please confirm the following details. Once you proceed you will be billed immediately for your first month of <strong><?php echo $transaction['L_NAME0']; ?></strong> at <strong>£<?php echo $transaction['L_AMT0']; ?>.</strong></p>
<p class="subheader">Additionally, you will be billed <strong>£<?php echo $transaction['L_AMT0']; ?></strong> on the <strong><?php echo date('j'); ?><sup><?php echo date('S'); ?></sup></strong> of each month, starting on <strong><?php echo getNextBillingDayHuman(); ?>.</strong></p>
<p class="subheader">If you're happy to proceed...</p>
<form method="post">
<input type="hidden" name="sub_id" value="<?php echo $transaction['INVNUM']; ?>" />
<input type="hidden" name="token" value="<?php echo $_GET['token']; ?>" />
<input type="hidden" name="PayerID" value="<?php echo $_GET['PayerID']; ?>" />
<input class="button" type="submit" name="activate_subscription" value="Activate Subscription" />
</form>
</div>
</div>
</div>
This line looks wrong to me:
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
Looking at other examples it should be:
if (<?php echo $totalValue ?>) {
var google_conversion_value = <?php echo totalValue ?>;
}
But, you aren't setting the value for $totalValue so maybe all conversions have equal value? In which case you should just use:
var google_conversion_value = 10;

Making Div tag resize according to browser size when using jquery.flashgallery to display the image gallery

<div id="banner">
<script type="text/javascript" src="gallery/js/jquery.js"></script>
<script type="text/javascript" src="gallery/js/swfobject.js"></script>
<script type="text/javascript" src="gallery/js/flashgallery.js"></script>
<script type="text/javascript">
jQuery.flashgallery('gallery/gallery.swf', 'gallery/config.xml',{ width:'100%', height:'100%', allowFullScreen: 'true', background: 'transparent'});
</script>
</div>
Here i want to make banner div to resize when i resize the browser window
can some body help on this Thanks..
My last post was by accident, try something like this. I have not tried it though.
$(window).resize(function() {
var divRatio = .7;
var divHeight = $(window).height()) * divRatio;
var divWidth = $(window).width()) * divRatio;
$('.yourDivYouWantHere').css({
height : divHeight;
width : divWidth;
});
}
Kevin

Php Facebook Canvas SWF object embed

Can anyone explain how to embed a swf object into a facebook canvas page via PHP.
<?php
function sswf($swf,$swfh,$swfw) {
echo "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0' ID=objects WIDTH=$swfw HEIGHT=$swfh><PARAM
NAME=movie VALUE='$swf'><EMBED src='$swf' WIDTH=$swfw HEIGHT=$swfh TYPE='application/x-shockwave-flash'
PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></OBJECT>";
}
$mf = "mmmm1.swf";
sswf($mf,690,1000);
?>
The code above no longer works although it did last week.... What's wrong with it?
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {allowFullScreen:'false', allowscriptaccess:'always', wmode:'opaque'};
var flashvars = {};
var attributes = { name:"xxx", id:"xxx" };
swfobject.embedSWF("xxx.swf?<? echo(time()) ?>", "xxx", "520", "500", "9.0", null, flashvars, params, attributes);
</script>
<div id="fb-root"></div>
<div id="xxx">
<h1>You need at least Flash Player 9 to view this page.</h1>
<p><img src="https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></p>
</div>

Categories