[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Can I run Google Analytics tracking code within a PHP web service script...???

Asked by angelleye in Search Engines, PHP Scripting Language, JavaScript

Tags: php javascript google analytics adwords conversion tracking

I'm trying to get Google Analytics E-Commerce and AdWords Conversion Tracking configured for my web site and I'm having some issues.  

I'm using PayPal's IPN (instant payment notification) system to process orders and I've got the analytics code dynamically generated within this script.  

I was a little worried at first that because the code is included in a page that never actually loads in a browser that might be the problem.  However, I found the following link that seems to prove otherwise:

http://books.google.com/books?id=eio4QY-wrEkC&pg=PA259&lpg=PA259&dq=paypal+ipn+adwords+conversion&source=bl&ots=htQ1hqeJ-2&sig=14lZc7DIYmrnWQK1NEclN5HamQY&hl=en&ei=PvQOSvTFJ4KMtgfRr7SNCA&sa=X&oi=book_result&ct=result&resnum=3#PPA259,M1

I've attached the PHP code that generates all of my google tracking code here.  I'm afraid I'm a dummy and I deleted the samples I had in my email box so I'll have to wait on some new orders to provide fresh samples of what actually gets generated from this code, however, I can tell you that when comparing it to Google's samples (http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=76305#ecommerce) it's the same.  Nothing shows up in my Analytics E-Commerce or AdWords conversion areas though.

Any information on how I can get this working would be greatly appreciated.  Thanks!!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
<?php
# Google Analytics E-Commerce Tracking Code
if(!$sandbox && $google_analytics_ecommerce && strtolower($payment_status) == 'completed')
{
	$js_output = '<script type="text/javascript">
			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
			document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
			</script>
			
			<script type="text/javascript">
			  var pageTracker = _gat._getTracker("' . $google_analytics_id . '");
			  pageTracker._trackPageview();
			  pageTracker._addTrans(
				"' . $invoice . '",           // Order ID
				"",                            // Affiliation
				"' . $mc_gross . '",           // Total
				"' . $tax . '",                // Tax
				"' . $shipping . '",           // Shipping
				"' . $address_city . '",       // City
				"' . $address_state . '",      // State
				"' . $address_country . '"     // Country
			  );';
		
	foreach($cart_items as $cart_item)
	{
		$js_output .= 'pageTracker._addItem(
				"' . $invoice . '",                                     // Order ID
				"' . $cart_item['item_number'] . '",                     // SKU
				"' . $cart_item['item_name'] . '",                       // Product Name 
				"",                            							 // Category
				"' . $cart_item['mc_gross'] . '",                        // Price
				"' . $cart_item['quantity'] . '"                         // Quantity
			  );';		
	}
			
	$js_output .= 'pageTracker._trackTrans();
			</script>';
			
	echo $js_output . chr(10) . chr(10);
}
 
$js_output_email = isset($js_output) ? $js_output : '';
 
# Google Analytics AdWords Conversion Tracking
if(!$sandbox && $google_adwords_conversions && strtolower($payment_status) == 'completed')
{
	$js_output = '<script language="JavaScript" type="text/javascript">
					<!--
					var google_conversion_id = ' . $google_adwords_conversion_id . ';
					var google_conversion_language = "en_US";
					var google_conversion_format = "3";
					var google_conversion_color = "ffffff";
					var google_conversion_label = "XNx1CM7GWBCmxJr2Aw";
					if (' . number_format($mc_gross,1) . ') {
					  var google_conversion_value = ' . number_format($mc_gross,1) . ';
					}
					//-->
					</script>
					<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js">
					</script>
					<noscript>
					<img height="1" width="1" border="0" src="https://www.googleadservices.com/pagead/conversion/' . $google_adwords_conversion_id . '/?value=' . number_format($mc_gross,1) . '&amp;label=XNx1CM7GWBCmxJr2Aw&amp;guid=ON&amp;script=0"/>
					</noscript>';
					
	echo $js_output;	
}
 
# Temp to see if this get reached
if(isset($js_output))
{
	$js_output_email .= $js_output;
	$mail -> Subject  =  'USBSwiper PayPal IPN : Google Analytics Code Ran';
	$mail -> Body =  $js_output_email;
	$mail -> AddAddress($admin_email_address, $admin_name);
	$mail -> Send();
	$mail -> ClearAddresses();	
}
?>
[+][-]05/21/09 03:33 AM, ID: 24439767Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Search Engines, PHP Scripting Language, JavaScript
Tags: php javascript google analytics adwords conversion tracking
Sign Up Now!
Solution Provided By: Tiggerito
Participating Experts: 1
Solution Grade: A
 
[+][-]05/21/09 03:45 AM, ID: 24439831Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/21/09 04:16 AM, ID: 24439990Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/21/09 04:35 AM, ID: 24440134Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/21/09 05:59 AM, ID: 24440827Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/21/09 03:08 PM, ID: 24446349Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07/08/09 01:48 AM, ID: 24801752Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625