Add onclick google analytics tracking

Hi

I need to insert the Google Analytics tracking code to track my goals and users who click on my menu. The problem is…my website is a one pager and the menu is generated from the pages I have created (not using wordpress menu’s).

If I go to my header, I find the following code which is related to my menu:

[php]

			<ul id="menu">

				<?php

					$page_argss = array('parent' => 0,'sort_order' => 'ASC', 'sort_column' => 'menu_order');

					$pagess = get_pages($page_argss); 

					$numberOfPages=0;



					foreach ($pagess as $single_pagee) {

						$pageIdd=$single_pagee->ID;

						$show_page_in_menuu =  get_post_meta($pageIdd , 'show_page_in_menu' , true);

						if($show_page_in_menuu != 'No') {

								$numberOfPages++;

						}

					}

				?>

				<?php

				$page_args = array('parent' => 0,'sort_order' => 'ASC', 'sort_column' => 'menu_order');

				$pages = get_pages($page_args); 

				$numberOfPagesInMenu=0;

				foreach ($pages as $single_page) {

						$trenutni="";

						//if(($menu_items==1)&&(!is_single())){ $trenutni=" current";}

						

						//$pageTemplate= get_post_meta($single_page->ID , 'page_template' , true);

						//if(($pageTemplate=='Blog')&&(is_single())){ $trenutni="class='current'";}	 

						

					  // $pageInMenu= get_post_meta($single_page->ID, 'show_page_in_menu' , true);

					  // $url_tab = "#"; 

					   //if (!is_front_page()){

						// $url_tab = get_option("siteurl")."#";

					  // }

					  // $menu_items++;

						

						$pageId=$single_page->ID;

						$children = get_pages('child_of='.$pageId.'&sort_column=menu_order&parent='.$pageId);

						

						$external_link =  get_post_meta($pageId , 'external_link' , true);

						$page_template =  get_post_meta($pageId , 'page_template' , true);

						$show_page_in_menu =  get_post_meta($pageId , 'show_page_in_menu' , true);

						if($show_page_in_menu != 'No') {

						

						$numberOfPagesInMenu++;

						$lastClass='';

						$lastClassSub=' class="with_ul" ';

						if($numberOfPagesInMenu == $numberOfPages) {

							$lastClass=' class="last" ';

							$lastClassSub=' class="with_ul last"   ';

						}

						

						

							$trenutni='';

							//if(($pageTemplate=='Blog')&&(is_single())){ $trenutni="class='current'"; }	 

							$url_tab='#!/';

							if (!is_front_page()){

							 $url_tab = get_option("siteurl")."#!/";

						   }

							if(count($children) == 0){  

								if ($external_link == '') {

									if ($page_template != 'Home') {

										echo '<li '.$lastClass.'><a href="'.$url_tab.''.$single_page->post_name .'">' . $single_page->post_title . '</a></li>';

									}

									else {

										echo '<li '.$lastClass.'><a href="'.$url_tab.'">' . $single_page->post_title . '</a></li>';

									}

								}

								else

								{

									echo '<li '.$lastClass.' ><a  href="'.$external_link.'" >' . $single_page->post_title . '</a></li>';

								}

							}

							if(count($children) != 0){  

								if ($external_link == '') {

									if ($page_template != 'Home') {

										echo '<li '.$lastClassSub.'><a href="'.$url_tab.''.$single_page->post_name .'">' . $single_page->post_title . '</a>';

									}

									else {

										echo '<li '.$lastClassSub.'><a href="'.$url_tab.'">' . $single_page->post_title . '</a>';

									}

								}

								else {

									echo '<li '.$lastClassSub.'><a href="'.$external_link.'">' . $single_page->post_title . '</a>';

								}

								echo '<ul class="submenu_1">';

								foreach($children as $child)

								{

									$subPageId=$child->ID;

									$grandChildren = get_pages('child_of='.$subPageId.'&sort_column=menu_order&parent='.$subPageId);

									$subPage_external_link =  get_post_meta($subPageId , 'external_link' , true);

									if(count($grandChildren) == 0){  

										if ($subPage_external_link == '') {

											echo  '<li><a href="'.$url_tab.''.$child->post_name.'">'.$child->post_title.'</a></li>';

										}

										else

										{

											echo  '<li><a href="'.$subPage_external_link.'">'.$child->post_title.'</a></li>';

										}

									}

									if(count($grandChildren) != 0){  

										if ($subPage_external_link == '') {

											echo  '<li><a href="'.$url_tab.''.$child->post_name.'">'.$child->post_title.'</a>';

										}

										else

										{

											echo  '<li><a href="'.$subPage_external_link.'">'.$child->post_title.'</a>';

										}

										

										echo '<ul class="submenu_2">';

										foreach($grandChildren as $grandChild)

										{

											$grandPageId=$grandChild->ID;

											$subPage_external_link_grand =  get_post_meta($grandPageId , 'external_link' , true);

										

												if ($subPage_external_link_grand == '') {

													echo  '<li><a href="'.$url_tab.''.$grandChild->post_name.'">'.$grandChild->post_title.'</a></li>';

												}

												else

												{

													echo  '<li><a href="'.$subPage_external_link_grand.'">'.$grandChild->post_title.'</a></li>';

												}

										}

										echo '</ul>';

										echo '</li>';

									}

									

						

								}

								echo '</ul>';

								echo '</li>';

							}

					 }

				}

				?>

			</ul>

		</nav>[/php]

I am trying to understand how and where I can add the following tracking code for my last menu item, the Contacts Page, so I can track who clicks and goes to that page:

[php]onclick="_gaq.push([’_trackEvent’, ‘Menu’, ‘clicked’, ‘submit’])";[/php]

I also can’t use GA’s direct link feature because my website is based on the wordpress template “Genius”, where the menu links change the url to /!#/

Anybody can help me? I’m not a PHP expert, I only understand the very basics…

Can you just track it by the querystrings?

Sponsor our Newsletter | Privacy Policy | Terms of Service