Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Arrow Include PHP onClick

    Hi there,

    *I recommend checking this small schematic about the problem: http://www.imageupload.org/?di=13129114988015

    I have a small question due to the fact that I only have moderate knowledge of PHP and JavaScript.

    Currently I have one PHP file containing every content of my site, they are all getting called with the include function.

    Problem is they are getting loaded even if the user doesn't click on the link; they get visible with JavaScript only when you click on the link.

    I do not have any performance or organisation issue, but my main problem is due to the fact that Google Analytics can't record that anyone clicked on a specific link because they are all on the same page.

    So, my solution is to add the Analytic code to each PHP include file and load them each time the user clicks!

    Is it possible and how can I do this?!

    Thanks!

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Can't be done with PHP.
    Look into using AJAX to call only the pages necessary. The extend of PHP for this is querystring handling, and thats all. PHP cannot interact with a browser, and therefore an onclick event will never fire.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Look into AJAX as this will allow Javascript and PHP to communicate and it will tell the Javascript to only include when the button is clicked.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #4
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ouch....... I have ZERO experience with AJAX....

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well my main problem is Analytics, cant I just do something to make it work so it can detect the pages witch the current architecture? The links to the other pages work with A HREF="#page1". Or can't I just do it in JavaScript ?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Those are all JS/HTML issues. I don't know a thing about how the google analytic's work I'm afraid, but other than not having the content on your page I don't know how to stop it. Someone else may have some better ideas, but I don't think you can resolve this with PHP.
    PHP cannot make use of a hash on a url, but it can make use of a querystring to determine what to show.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Aiight! Well Analytic work but puting a JScript on each page that gets loaded so.... I'll try to look onto AJAX.. if anyone else has any idea ?!

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    AJAX sounds the best to me.
    Its a piece of cake to use, just takes some practice of dom traversing. If the links are already there to show something, it won't be difficult to alter it to use the ajax to load the data instead.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    technofou (12-01-2010)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •