I am using Google Adwords to push and track subscriber acquisitions on my site, but can not get the conversion reporting to work.
Here is my setup.
My subscribe form is dynamically loaded on my subscribe page by a Wordpress plugin I created. After validation the form is replaced with a thank you message with php, so the user is not redirected to a confirmation page. Because of this, I think I need to check for the output of a conversion value to get Adwords to report.
I have followed the adwords help docs and have made the reporting a "purchase/sale" tracking so I can test for the conversion_value variable.
Here is my plugin code that outputs the thank you message.
//****[ Variable Conversion Value For Google AdWords]****
$variableConversionValue = '<h3 class="subscribeConfirm">Thanks for signing up!</h3>';
//****[ After writing subscriber data, display thank you message****
echo $variableConversionValue;
Here is my Adwords Tracking (did not include generic tracking code) that is on my subscribe page (is a php page, but the tracking in not contained within php tags).
if (<? echo $variableConversionValue; ?>) {
google_conversion_value = <? echo $variableConversionValue; ?>;
}
Can you please help me get the reporting to work? Thanks!
I'm not sure you are understanding the purpose of the conversion values. If you are looking for a binary "the conversion occurred", I'm not sure you need to specify a value at all, but if you do, you should be using a number like 1 or whatever you feel the dollar value of a lead is. I may be wrong, but I don't think Adwords will be able to process text/html in the value as anything meaningful.
If your code for checking the form and output are in two different places (as it looks like from above), maybe what you really want in your output is:
if (<? echo $variableConversionValue; ?>) {
google_conversion_value = <? echo '1'; ?>;
}
I have figured it out.
When viewing my live page source with the code above, the echo $variableConversionVale code was blank, meaning it was not carrying the value over correctly. So instead of using the variable, I put in exactly what would be displayed to track the conversion.
Example:
if ('<h3 class="subscribeConfirm">Thanks for signing up!</h3>') {
google_conversion_value = '<h3 class="subscribeConfirm">Thanks for signing up!</h3>'; />
}
Using the above code, it tracks a conversion only when the confirmation that you have been subscribed pops up.
Reference link here under step 4 "Different scenarios for inserting the code snippet"
Thanks!
Related
I am using wordpress for a web site. I am using snippets (my own custom php code) to fetch data from a database and echo that data onto my web site.
if($_GET['commentID'] && is_numeric($_GET['commentID'])){
$comment_id=$_GET['commentID'];
$sql="SELECT comments FROM database WHERE commentID=$comment_id";
$result=$database->get_results($sql);
echo "<dl><dt>Comments:</dt>";
foreach($result as $item):
echo "<dd>".$item->comment."</dd>";
endforeach;
echo "</dl>";
}
This specific page reads an ID from the URL and shows all comments related to that ID. In most cases, these comments are texts. But some comments should be able to point to other pages on my web site.
For example, I would like to be able to input into the comment-field in the database:
This is a magnificent comment. You should also check out this other section for more information
where getURLtoSectionPage() is a function I have declared in my functions.php to provide the static URLs to each section of my home page in order to prevent broken links if I change my URL pattern in the future.
I do not want to do this by using eval(), and I have not been able to accomplish this by using output buffers either. I would be grateful for any hints as to how I can get this working as safely and cleanly as possible. I do not wish to execute any custom php code, only make function calls to my already existing functions which validates input parameters.
Update:
Thanks for your replies. I have been thinking of this problem a lot, and spent the evening experimenting, and I have come up with the following solution.
My SQL "shortcode":
This is a magnificent comment. You should also check out this other section for more information
My php snippet in wordpress:
ob_start();
// All my code that echo content to my page comes here
// Retrieve ID from url
// Echo all page contents
// Finished generating page contents
$entire_page=ob_get_clean();
replaceInternalLinks($entire_page);
PHP function in my functions.php in wordpress
if(!function_exists("replaceInternalLinks")){
function replaceInternalLinks($reference){
mb_ereg_search_init($reference,"\[custom_func:([^\]]*):([^\]]*)\]");
if(mb_ereg_search()){
$matches = mb_ereg_search_getregs(); //get first result
do{
if($matches[1]=="getURLtoSectionPage" && is_numeric($matches[2])){
$reference=str_replace($matches[0],getURLtoSectionPage($matches[2]),$reference);
}else{
echo "Help! An unvalid function has been inserted into my tables. Have I been hacked?";
}
$matches = mb_ereg_search_regs();//get next result
}while($matches);
}
echo $reference;
}
}
This way I can decide which functions it is possible to call via the shortcode format and can validate that only integer references can be used.
I am safe now?
Don't store the code in the database, store the ID, then process it when you need to. BTW, I'm assuming you really need it to be dynamic, and you can't just store the final URL.
So, I'd change your example comment-field text to something like:
This is a magnificent comment. You should also check out this other section for more information
Then, when you need to display that text, do something like a regular expression search-replace on 'href="#comment-([0-9]+)"', calling your getURLtoSectionPage() function at that point.
Does that make sense?
I do not want to do this by using eval(), and I have not been able to accomplish this by using output buffers either. I would be grateful for any hints as to how I can get this working as safely and cleanly as possible. I do not wish to execute any custom php code, only make function calls to my already existing functions which validates input parameters.
Eval is a terrible approach, as is allowing people to submit raw PHP at all. It's highly error-prone and the results of an error could be catastrophic (and that's without even considering the possibly that code designed by a malicious attacker gets submitted).
You need to use something custom. Possibly something inspired by BBCode.
I'm pretty new to HTML and javascript. I know this code already exist on internet but I can't have it working for me. I'm stuck on this issue for 2-3 days. I would be really glad if you could help me out.
Here is my problem
I want to populate the optCategory select list based on the selected entry of optPostAppliedFor. For that I called a function change_categoriees(key) when I click the optPostAppliedFor list. The code is here as follows
<tr>
<td width="40%" align="right" nowrap>
<strong>
Post Applied for<span class="text11red">*</span> :
</strong>
</td>
<td width="60%">
<select name="optPostAppliedFor" class="flat" onclick="change_categories(0);" />
<option value="">--Select--</option>
<?php
foreach($App['post_applied_for'] as $key => $val){
echo '<option value="'.($key).'">'.$val.'</option>';
}
?>
</select>
</td>
</tr>
Here is php code for default enteries of optPostAppliedFor and optCategory
$App['post_applied_for'] = array(
'Lecturer' => 'Lecturer',
'Business Analyst' => 'Business Analyst',
'Deepender good' => 'Deepender good'
);
$App['category'] = array(
'Category1' => 'Category1',
'Category2' => 'Category2',
'Category3' => 'Category3'
);
Please tell me how can I make this function, so that my purpose is achieved. I tried this but all in vain.
function change_categoriees(key) {
alert('asdasd');
var z = document.getElementById('optCategory');
var x = document.getElementById('optPostAppliedFor');
var y = document.createElement('option');
var display = x.options[x.selectedIndex].text;
var option = x.options[x.selectedIndex].value;
y.text = display;
y.value = option;
try {
z.add(y,null);
} catch(ex) {
z.add(y);
}
z.options[0].text = '* '+(z.length-1)+' selected *';
}
I'm not really sure, but...
These two lines in your change_categoriees method look problematic:
var z = document.getElementById('optCategory');
var x = document.getElementById('optPostAppliedFor');
For these statements to return some value, your HTML needs to have id attributes with the names optCategory and optPostAppliedFor:
<select id="optPostAppliedFor">
Also note that the PHP code runs on the back end, in the server. There's no way that the javascript running in the browser can call PHP directly.
If I interpret your code correctly, you do have a slight problem : you're putting variable in the PHP code, that you'd like the client (the browser) to use. It's not the way it works. Variable in PHP are only stored on the server-side. So the Javascript (which is on the browser side) cannot use it in any way, if you only store them as variables : they'll be on the server memory, not on the client's. There are two solutions here :
1°) You put the variable you're going to use in the web page that PHP generates. You could go with hidden fields, for instance, and then "unhide" the relevant fields. But if you got a lot of variables, it's not very practical.
2°) You could go with an AJAX solution : basically, the idea is that through Javascript, you call a PHP script that is going to send back information (formatted as pure text, XML or JSON). Here, when the user clicks on the first list, you send a request (POST or GET) where you'll inform the server about the choice of the user. For instance, you'll ask for the categories connected to the "Business Analyst" choice. The PHP script we'll analyse the "post applied for" and send the content of the category list accordingly. Since everything is done through Javascript & PHP, the page will not be reloaded during this time, so it's relatively fluid.
I would recommend the use of a Javascript library to make things a bit easier. JQuery being one of the most popular choice, you will find a lot of help and example on the web.
May be you are searching for AJAX methods? E.g. you send request to some of your PHP files with GET or POST variable for your key (which user selects in optPostAppliedFor) and that PHP script echo'es the needed result, so JS could use it.
For example, with jQuery this would look like this:
$("select[name=optCategory]").load("myUberScript.php", { key: $("select[name=optPostAppliedFor]").attr("selected") });
myUberScript.php:
<?php
$key = $_POST['key'];
if (isset($key))
{
if ($key == 'moo')
echo "<option>moo</option>"; else
if ($key == 'foo')
echo "<option>foo</option>";
}
?>
I think this would be the best way, but i'm really not sure with my .attr("selected") selector. And i recommend you to read something 'bout AJAX and jQuery - these are very useful when web-developing =)
So, what does this JS do? It finds your select tag with name optPostAppliedFor, gets all its 'selected' items (be sure to verify that code - i am not sure about it), sends POST request to myUberScript.php passing that values as $_POST['key'] argument, gets response, finds div named optCategory and sets its inner HTML code to PHP's response. Pretty nice, huh? =)
I recommend this way beacause it is not always good for user to get all the internal data within javascript - user could see that data and if there is a lot of data, the page would load slooowly. Second: you can manage/edit/update/modify (choose the right one) your PHP code whenever you want. Third: PHP code has more features for secure verifying user' data and lots more. But there is one great disadvantage: if user disables JS support in his browser, you would not be able to do this sort of trick. Notice: this is a very rare case when user disables JS =)
As a first problem, in your PHP code, you improperly close the select tag, like this,
<select ... />
...
</select>
That will probably cause some errors. It should be like this, without the extra /,
<select ... >
...
</select>
As another problem, you spell your function call like this,
onclick="change_categories(0);"
but you misspell your function name like this,
function change_categoriees(key) {...}
Notice the extra "e" in "categoriees". So you're not actually calling the function properly.
It looks like other people have some answers too, so I'll just finish by offering some suggestions for dev tools and documentation. For development tools, Firefox Firebug is excellent, it will let you debug css, html, and javascript. I've also heard good things about the development tools in Chrome. In fact, all the newest browser versions have development tools of some sort, and they're all pretty good.
Next, the Mozilla docs are a good resource for web-development. You might also be interested in checking out the resources mentioned at w3fools.com.
Also, in the future, when sharing code on Stack Overflow, you should consider sharing a live example with jsFiddle.
Oh wait, before I forget, you should also use a text editor or an IDE that does syntax highlighting, and maybe even syntax correction, for you. I use a simple text-editor called Notepad++ for Windows, though there are many others.
I know that I was already posted similar question but I just can't find the answer and figure it out how to solve this problem.
I'm trying to customize Jquery Star Rating plugin (link text) but I do not know what to do to show the message based on response of PHP script.
Jquery script successfully send rating data to PHP scripts that query the database and based on that echo message of proper or improper rating.
What should I add to an existing JS code so I can get echo from PHP and base on that write a message on some DIV beside rating star?
Jquery:
$('#gal').rating('gl.php?gal_no=<?=$gal_no;?>&id=<?=$id;?>', {maxvalue:10,increment:.5, curvalue: <?=$cur;?>});
Simplified PHP code:
$br=mysql_query("SELECT count(gal) as total FROM ...")
if ... {
echo '0';
}
else echo '1';
}
Jquery code successfully transmitted data to PHP script and when the PHP done with checking data echo the result ('1' or '0'). How can I get this PHP result back to Jquery and based on them write a message? Something like:
if(data=="1")
{
$("#error").show("fast").html('not correct').css({'background-color':'#F5F5F5','border-color' : '#F69'});
}else{
$("#error").show("fast").html('correct').css({'background-color' : '#FFF','border-color' : '#3b5998'});
}
If someone has an idea...I would appreciate it.
You would have to modify the source of the rating plug-in, as it does not provide any way for you to handle return values of your script. Read the documentation of jquery.post method in jquery, and then try to understand rating's code. Notice that when calling post method rating plugin doesn't provide a callback method (in other words it just doesn't care what your php script returns). You could try to modify the code in such way, that it allows you to register your own callback method.
I have used "echo $query" to see whether it is getting value or not but it is not showing anything on the page. What is the other way to see what value it is getting?
I use Aptana Studio 2.0 PDT but I am not able to set the breakpoints. Quite new in it.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$ulName = $_GET['ControlName'];
$query = $_GET['SqlQuery'];
echo $query;
mysql_connect('localhost:3306','pffsddsf','dfsdfsd');
mysql_select_db('publicdb');
$result=mysql_query("select * from electioncategorymaster");
?>
<ul id="<?php echo $ulName; ?>" name="<?php echo $ulName; ?>">
<?php while($row=mysql_fetch_array($result))
{ ?>
<li><?php echo $row[1]; ?></li>
<?php } ?>
</ul>
You may not be getting the parameters you expect, so start your script with
var_dump($_GET);
to see what your page is actually getting.
While I appreciate you are just learning, accepting parameters which are passed verbatim to the database server and to the client browser is a security no-no.
Take the $ulName variable - I could inject HTML of my choosing there, so why not constrain it to alphanumerics?
if (preg_match('/[^a-z0-9_]/i', $ulName)
die("Invalid ControlName specified");
As for accepting SQL via a parameter, I really wouldn't do that unless you trust the user of your application completely....
?SqlQuery=DROP+DATABASE+publicdb
Scary right? Now how about if you combined both these flaws? I could craft a link which displayed your page, but embedded a form with hidden fields containing that query, along which a big button which said "click me for funny cat videos". Now I just need to send the link out there and wait for someone else to do my evil bidding :)
Try var_dump($query); (will also report/show empty strings)
If your page is completely blank a look into your apache (or webserver of your choice) errorlogs could also be helpful.
try this:
var_dump($query);
exit;
and see what's happens.
This may sound useless, but you should also copy in an 'example' URL that you are using.
PHP is case-sensitive (especially when it comes to array keys) so for one, I would check that the URL that you are calling is using the correct case when it comes to the GET parameters.
When this simple method fails to show any value the question naturally arises: "Is echo working or is there no value to display?"
I did something similar a while ago, but rather than use echo, I used
printf("[%s]", $query);
So I could see the empty [] when there was no value returned by $_GET
first: enable error logging and also log to a logfile.
error_reporting(E_ALL);
ini_set('display_errors','On');
you can try if your error logging is working by doing the following:
error_log("This Error should be displayed!", 0);
see more about error handling and logging on the php.net site: http://www.php.net/manual/en/book.errorfunc.php
How do i make PHP work with JS?
I mean more like, i want to check if the user is logged in or not,
and if he is then it will:
$("#message").fadeIn("slow"); ..
How should i do this?
I have an idea maybe have a file that checks it in php, and then it echo out 1 or 0.
And then a script that checks if its getting 1 then do the message fade in.. But im not as so experienced to script that in JS
You cannot directly pass variables from Javascript to PHP because the PHP run on the server before it's sent to the client. But you can 'pass' variables from PHP to Javascript.
For example:
echo('<script type="text/javascript'> var phpvar = '.$variablefromphp.';</script>');
However, you can manipulate what javascript your browser will print. You can first check if the user is logged in in PHP, and based on that, conditionally print the HTML and Javascript.
For example
if($user->logged_in())
{
echo('<script type="text/javascript">$("#message").fadeIn("slow");</script>');
}
else
{
//php function
generateLoginBox();
}
I only javascript to enhance user experience. You should make your application work even when javascript turned off.
With the javascript enabled, you can add an enhanced experience, such as animated page element, AJAX request, etc.
In case of login state, you should have a way to know it in PHP script. Then in the output, you can have a conditional block that only executed if the login state is true. You can put anything you want here.
Javascript can be working in a static HTML page. You can use this to create a simple test for the code that you wrote, to see if it working as you want. Read the documentation in http://www.jquery.com/, there are many links there to many examples.