We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7239
    • 14 Posts
    I use ModX evolution and I am looking for the best way to handle/track visitors filling out a form on my site. Basically When some visits my site from a Google ad-words ad, they might browse through a few pages on my site and fill out my form, I want to know that they came from Google, and if a visitor came to my site from Yahoo I would like to know they came from Yahoo, and Bing ect...

    What would be the best way to accomplish this with ModX Evolution?

    Any help pointing me in the right direction would be greatly appreciated.

    Thanks,

    -Eric
    • Hello,

      This would likely be something to do with a cookie or session. Just have a snippet to record the entry information and store in cookie/session, then insert that in your form later.
        Patrick | Server Wrangler
        About Me: Website | TweetsMODX Hosting
        • 3749
        • 24,544 Posts
        You’ll want to make sure you only save the referer once. Something like this:

        <?php
        /* GetUrl snippet */
        
        /* make sure we don't already have it */
        if(!isset($_SESSION[’referer’])){
        
         /*get the URL the user came from */
        
            if ($_SERVER[’HTTP_REFERER’]){
                $referer = $_SERVER[’HTTP_REFERER’];
            } else {
                $referer = “unknown”;
            }
        // save it in the $_SESSION variable
            $_SESSION[’referer’] = $referer; 
        }
        ?>


        If you put [!GetUrl!] near the top of your template, you can check the referer further down on any page with something like this:

        <?php
        if (stristr($_SESSION['referer'],'google')) {
        
           return "User came from Google";
        }
        ?>


        Note that, unlike the real world, in the land of PHP it’s "referer" not "referrer" wink
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting