Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: Contatore di click

  1. #1

    Contatore di click

    Ciao a tutti,
    sto cercando di realizzare uno script in php che permetta di contare il numero di click su un banner. Il problema è che il banner è generato dal seguente codice javascript, di un circuito pubblicitario pay per click:

    <script language="javascript" type="text/javascript">
    document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"><\/s'+'cript>');
    </script>


    Ho pensato che la soluzione sia di aprire, cliccando sul banner, oltre alla finestra del sito pubblicizzato dal banner stesso una piccola finestra con codice php che effettua il conteggio dei click.
    Sono giorni che ci penso sopra, ma non riesco proprio a capire come fare .
    Aiuto!!!

  2. #2
    Il problema è: riesci ad identificare univocamente ogni singolo banner? Altrimenti credo che il problema non ha soluzione.
    I dilettanti costruirono l'Arca, i professionisti il Titanic!

  3. #3
    No, il banner è generato dal codice javascript e varia di volta in volta. Ma a me non serve contare il numero di click che ha ricevuto il singolo banner. Quello che voglio fare è contare il numero di click che hanno ricevuto tutti i banner generati da quel codice, senza fare distinzione tra un banner e l'altro.

  4. #4

    .........

    Ciao.
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="javascript" type="text/javascript">
    function 
    testScript()
    {
        var 
    nScripts document.getElementsByTagName('script');
        for(var 
    i=0;i<nScripts.length;i++)
        {
            if(
    typeof nScripts[i].getAttribute('src')=='string')
            {
                
    alert(nScripts[i].getAttribute('src'));
            }
        }

    }
    function 
    addEvent(elmevTypefnuseCapture)
    {
            if (
    elm.addEventListener)
            {
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
            } else if (
    elm.attachEvent) {
                var 
    elm.attachEvent('on' evTypefn);
                return 
    r;
            } else {
                
    elm['on' evType] = fn;
            }
    };
    addEvent(window,'load',testScriptfalse);
    </script>

    </head>

    <body>
    <script language="javascript" type="text/javascript">
    document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"><\/s'+'cript>');
    </script>
    </body>
    </html> 
    Lo colleghi ad ajax che richiama una pagina
    PHP e dovresti risolvere.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  5. #5

    .............


    Questa magari funziona meglio


    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="javascript" type="text/javascript">
    function 
    testScript()
    {
        
    addEvent(document.getElementsByTagName('body')[0], 'click'provafalse);
    }
    function 
    prova(e)
    {
        
    target getTarget(e);
        
    alert(target.getAttribute('src'));
    }
    function 
    addEvent(elmevTypefnuseCapture)
    {
            if (
    elm.addEventListener)
            {
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
            } else if (
    elm.attachEvent) {
                var 
    elm.attachEvent('on' evTypefn);
                return 
    r;
            } else {
                
    elm['on' evType] = fn;
            }
    };
    function 
    getTarget(e)
    {
            var 
    target window.event window.event.srcElement e.target null;
            if (!
    target){return false;}
            return 
    target;
    };
    addEvent(window,'load',testScriptfalse);
    </script>

    </head>

    <body>
    <script language="javascript" type="text/javascript">
    document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"><\/s'+'cript>');
    </script>
    </body>
    </html> 

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  6. #6
    Scusami, ma non sono molto pratico di javascript e ajax.
    Con i due script che mi hai postato riesco anche a passare a un database una variabile contenuta in un cookie?
    Grazie.

  7. #7

    .........

    Ciao.
    Tieni in considerazione solamente
    il secondo pezzo di codice.
    Questo è ancora un passo in avanti
    guarda cosa riesci a combinare.
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="javascript" type="text/javascript">
    function 
    testScript()
    {
        
    addEvent(document.getElementsByTagName('body')[0], 'click'provafalse);
    }
    function 
    prova(e)
    {
        var 
    addClick 0;
        
    target getTarget(e);
        if(
    target.tagName.toLowerCase()=='img')
        {
            
    //Qui devi trovare qc per gestire l'attributo src
            //perchè cambia di volta in volta questo è un'esempio
            
    if(target.getAttribute('src').indexOf('trade'))
            {
                
    addClick 1;
            }
         }
        
    alert(addClick);
    //addClick poi la puoi passare (se è uguale ad 1) tramite ajax ad una pagina
    // php in cui fai una la tua bella query e aggiorni il valore numClicks
    }
    function 
    addEvent(elmevTypefnuseCapture)
    {
            if (
    elm.addEventListener)
            {
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
            } else if (
    elm.attachEvent) {
                var 
    elm.attachEvent('on' evTypefn);
                return 
    r;
            } else {
                
    elm['on' evType] = fn;
            }
    };
    function 
    getTarget(e)
    {
            var 
    target window.event window.event.srcElement e.target null;
            if (!
    target){return false;}
            return 
    target;
    };
    addEvent(window,'load',testScriptfalse);
    </script>

    </head>

    <body>
    <script language="javascript" type="text/javascript">
    document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"></s'+'cript>');
    </script>
    </body>
    </html> 
    Con i due script che mi hai postato riesco anche a passare a un database una variabile contenuta in un cookie?
    Se il banner mette un cookie nel client non ci dovrebbero
    essere problemi (penso bisogna provarci ).

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  8. #8

    ........

    Il cookie è dinamico ma ha al suo
    interno chiamiamola costante
    ad.altervista.org quindi non ci dovrebbero
    essere problemi.
    Ad ogni modo non ne vedo l'utilità
    una cosa + furba sarebbe recuperare l'ip
    del client ed inserire quello.

    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  9. #9
    Come devo fare a passare la variabile addClick tramite ajax? Mi puoi postare due righe?

  10. #10

    ...........

    Tirato via quindi ci potrebbe essere
    qc tanto per darti un'idea:
    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    title>Box per le news by Whisher</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    script language="JavaScript" type="text/javascript">
        var 
    page "file.php";//File delle news formato  news uno | news due | etc
        //Gets the browser specific XmlHttpRequest Object
        
    function getXmlHttpRequestObject() {
            var 
    receiveReq=false//Clear our fetching variable
            
    try {
                    
    receiveReq = new ActiveXObject('Msxml2.XMLHTTP'); //Try the first kind of active x object…
            
    } catch (e) {
                    try {
                            
    receiveReq = new ActiveXObject('Microsoft.XMLHTTP'); //Try the second kind of active x object
                
    } catch (e) {
                    
    receiveReq false;
                            }
            }
            if (!
    receiveReq && typeof XMLHttpRequest!='undefined') {
                   
    receiveReq = new XMLHttpRequest(); //If we were able to get a working active x object, start an XMLHttpRequest
            
    }
            return 
    receiveReq;
        }            
        
    //Get our browser specific XmlHttpRequest object.
        
    var receiveReq getXmlHttpRequestObject();        
        
    //Initiate the asyncronous request.
        
    function getNews(getValue) {
            
    //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
            
    if (receiveReq.readyState == || receiveReq.readyState == 0) {
                
    //Setup the connection as a GET call to your page
                //True explicity sets the request to asyncronous (default).
                 
    var url page+"?add=" getValue;
                
    receiveReq.open('GET'url true);
                
    //Set the function that will be called when the XmlHttpRequest objects state changes.
                
    receiveReq.onreadystatechange handlegetNews
                
    //Make the actual request.
                
    receiveReq.send(null);
            }            
        }
        
    //Called every time our XmlHttpRequest objects state changes.
        
    function handlegetNews() {
            
    //Check to see if the XmlHttpRequests state is finished.
            
    if (receiveReq.readyState == 4) {
                
    //Set the contents of our span element to the result of the asyncronous call.

                
    var text receiveReq.responseText;
    alerttext);
            }
    }
    function 
    testScript()
    {
        
    addEvent(document.getElementsByTagName('body')[0], 'click'provafalse);
    }
    function 
    prova(e)
    {
        var 
    addClick 0;
        
    target getTarget(e);
        if(
    target.tagName.toLowerCase()=='img')
        {
            
    //Qui devi trovare qc per gestire l'attributo src
            //perchè cambia di volta in volta questo è un'esempio
            
    if(target.getAttribute('src').indexOf('trade'))
            {
                
    addClick 1;
            }
         }
       
    getNews(addClick);
    }
    function 
    addEvent(elmevTypefnuseCapture)
    {
            if (
    elm.addEventListener)
            {
                
    elm.addEventListener(evTypefnuseCapture);
                return 
    true;
            } else if (
    elm.attachEvent) {
                var 
    elm.attachEvent('on' evTypefn);
                return 
    r;
            } else {
                
    elm['on' evType] = fn;
            }
    };
    function 
    getTarget(e)
    {
            var 
    target window.event window.event.srcElement e.target null;
            if (!
    target){return false;}
            return 
    target;
    };
    addEvent(window,'load',testScriptfalse);
    </script>
        </head>
        <body>
            
            <script language="javascript" type="text/javascript">
    document.write('<s'+'cript language="javascript" src="http://ad.altervista.org/alternet.ad?c=1&f=0&'+new Date().getTime()+'"></s'+'cript>');
    </script> 
        </body>
    </html> 
    e il semplice file.php per vedere se tutto funzia
    Codice PHP:
    <?php 
    echo $_GET['add'];
    ?>
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.