LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-24-2013, 03:07 PM   #1
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Rep: Reputation: 22
Question Google Event Tracking


I need help 'cos I don't know java enough to split this small script up.
I got a website that where I first installed google Event Tracking in to see how many
shows there is on that site.

I got this small script from google at the bottom in the index.php file:

Code:
...

</div>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'XX-88888888-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</body>
</html>
Now I want to do almost the same 'gaq.push' but in another place and that code looks something like this:

Code:
if (substr($d['image'],0,4)=="http"){
   return '
           <div class="images">
           <a href=clicks.php?id='.$d['id'].' target="_blank" >
           <img name="WE" src="'.$d['image'].'" alt="'.$d['view'].'" 
                width="913" height="61" margin: 0 auto;
                />
                </a>
            </div>';
            }

now I want to add this:
Quote:
onclick="_gaq.push([\'_trackEvent\', \'category\', \'action\', \'label\']);"
in there and I tried but it didn't work, but no errors just that google didn't get any of the info.
I think the '(function() {...' from the first code shown needs to be there somewhere too but I don't know how to split this up and need help.
Best thing would be if I could place the '(function() {...' in a separate .js file that I can place with the rest of the
scripts and then use that elsewhere when ever needed... somehow.

Can anyone help me out with this?

Last edited by Basher52; 09-24-2013 at 03:15 PM.
 
Old 09-26-2013, 06:50 AM   #2
PeterSullivan
LQ Newbie
 
Registered: Aug 2013
Posts: 29

Rep: Reputation: Disabled
Quote:
Originally Posted by Basher52 View Post
I need help 'cos I don't know java enough to split this small script up.
I got a website that where I first installed google Event Tracking in to see how many
shows there is on that site.

I got this small script from google at the bottom in the index.php file:

Code:
...

</div>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'XX-88888888-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</body>
</html>
Now I want to do almost the same 'gaq.push' but in another place and that code looks something like this:

Code:
if (substr($d['image'],0,4)=="http"){
   return '
           <div class="images">
           <a href=clicks.php?id='.$d['id'].' target="_blank" >
           <img name="WE" src="'.$d['image'].'" alt="'.$d['view'].'" 
                width="913" height="61" margin: 0 auto;
                />
                </a>
            </div>';
            }

now I want to add this:
in there and I tried but it didn't work, but no errors just that google didn't get any of the info.
I think the '(function() {...' from the first code shown needs to be there somewhere too but I don't know how to split this up and need help.
Best thing would be if I could place the '(function() {...' in a separate .js file that I can place with the rest of the
scripts and then use that elsewhere when ever needed... somehow.

Can anyone help me out with this?

What is the other code is, i think google is providing only one code for the event tracking.
 
Old 09-26-2013, 01:12 PM   #3
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Original Poster
Rep: Reputation: 22
What I meant by the first code shown was this:
Code:
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'XX-88888888-8']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
I know I can only use the the _gaq.push(... but am I wrong to think that the function below that is the one being called hence calling google to run ga.js?
What I want to do is to split that function into a separate js-file that I can place in the script directory and later use that when I need to do a _gaq.push

Does that make more sense?
 
Old 09-26-2013, 01:19 PM   #4
Basher52
Member
 
Registered: Mar 2004
Location: .SE
Distribution: Arch
Posts: 401

Original Poster
Rep: Reputation: 22
I mean something like this....:

Code:
<div class="images">
           <a href=clicks.php?id='.$d['id'].' target="_blank" onclick="_gaq.push([\'_trackEvent\', \'image\', \'click\', '.$d['image'].']);" >
           <img name="WE" src="'.$d['image'].'" alt="'.$d['view'].'" 
                width="913" height="61" margin: 0 auto;
                />
                </a>
            </div>';
(my code in red) but in this case the '(function() {...'-part of the script is gone so it can't work.

That's why I need to get that function into a script file for later easy access to it from everywhere.

Last edited by Basher52; 09-26-2013 at 01:21 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Google Is Exploring an Alternative to Cookies for Ad Tracking LXer Syndicated Linux News 0 09-21-2013 04:00 PM
LXer: Google launches its third junior Code-in event LXer Syndicated Linux News 0 09-26-2012 09:10 AM
add past event with googlecl to Google Calendar m4rtin Linux - Software 0 08-22-2010 06:41 PM
LXer: Live From Google Chrome OS Event (Info and Screenshots) LXer Syndicated Linux News 0 11-19-2009 01:41 PM
Event tracking s3bas Linux - Newbie 2 04-18-2009 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration