Add sites to Piwik automatically

Discussion in 'Black Hat SEO Tools' started by anhkiet, Sep 20, 2012.

  1. anhkiet

    anhkiet Newbie

    Aug 18, 2012
    Likes Received:
    Home Page:
    I will try something I have not done before. I will release personal scripts that I use to help others who cannot program. If this is too time consuming due to support, I will stop it. This first release is a hook for adding sites to piwik (1.8.4) passively. When it encounters a domain that it can't match to what's in the database, it adds it automagically. I tried to post example, but the damn thing won't let me because it contains URLs. Essentially it looks at the URL to see if it knows about the site, and if it does not, it adds it to Piwik.

    [remove]Originally I wanted to post the code here, but I thought it would be inconvenient for me to update/document the changes in the future, so I've put it on a new blog I setup[/remove], I guess I'll add the code here because I can't link out. What a frustrating experience. You can see the blog post URL if you run this in your address bar, be sure the javascript: portion does not get stripped out:

    javascript: a=[];a.push('mutedsignals');a.push(['c','o','m'].join(''));a.unshift('www');a.join('.')+['','software','automatically-add-websites-in-piwik',''].join('/')
    Anyway, this should theoretically work with the existing tracking code but it is not guaranteed to be backward compatible. I recommend saving this file to track.php and test it out separately, I've put sample javascript tracking code in my blog post if you are so inclined. I might put all of this on github for ease of maintainability in the future if anyone is interested.

    // Put this into your piwik.php

    function getId($url) {
    $parts parse_url(strtolower($url));
    $name $parts['host'];
    $url "$parts[scheme]://$parts[host]";
    $request = new Piwik_API_Request("
    $result $request->process();
    $ids unserialize($result);
      if (
    count($ids) === 1) {
      } else if (
    count($ids) < 1) {
    $request = new Piwik_API_Request("
    $result $request->process();
    // ... later in the file, after all the other require_once ...
    require_once PIWIK_INCLUDE_PATH .'/core/API/Request.php';
    PIWIK_INCLUDE_PATH .'/core/Loader.php';
    // ... then before the tracking code, the last if block ...
    $_GET['idsite'] = getId($_GET['url']);
    • Thanks Thanks x 3