Matomo-ProtectTrackID icon indicating copy to clipboard operation
Matomo-ProtectTrackID copied to clipboard

Get hashed site ID via API

Open Acen opened this issue 9 years ago • 9 comments

The ability to get the hashed siteID from the API, perhaps an addon to the SitesManager module?

Acen avatar Oct 05 '16 02:10 Acen

In the interim, I've just made something which takes it from the getJavascriptTag function.

    public function getHashedSiteId($id)
    {
        $js_tag = json_decode($this->postRequest('SitesManager.getJavascriptTag', array(
            'idSite' => $id
        )), true);
        return substr($js_tag['value'], strpos($js_tag['value'], 'idsite=') + 7, 8);
    }

Acen avatar Oct 05 '16 03:10 Acen

Thanks @Acen. I will provide this on next release.

joubertredrat avatar Oct 05 '16 10:10 joubertredrat

Hi @Acen

What API call are you using for query? I remade plugin for new Piwik version and on API calls SitesManager.getJavascriptTag and SitesManager.getImageTrackingCode now is getting code with siteId hashed.

joubertredrat avatar Oct 21 '16 13:10 joubertredrat

Hey @joubertredrat, I'm using getJavascriptTag and it is indeed getting the hashed ID as part of the entire javascript block.

I'm just needing the hashed ID however to store into an external database and query against later. 👍

Acen avatar Nov 01 '16 03:11 Acen

Hi @Acen No problem, this was fixed on new version, https://github.com/joubertredrat/Piwik-ProtectTrackID/releases/tag/1.0.0

But see description with attention because you will need make backup of settings.

joubertredrat avatar Nov 01 '16 11:11 joubertredrat

@Acen explain to me, you need a API call to get only a hashed id from idSite?

joubertredrat avatar Nov 01 '16 11:11 joubertredrat

Sorry, I really am terrible at following up on Github issues. But you're correct. I just need the hashed ID via an API call so I can store it locally in my own application's database.

For example, something like SitesManager.getHashedID or even perhaps SitesManager.getID

Acen avatar Dec 05 '16 21:12 Acen

Hi @Acen

I will see if is possible to add new method calls on API for plugin.

joubertredrat avatar Dec 05 '16 23:12 joubertredrat

Thanks @Acen for reporting this.

This is such an important feature that is missing when sites are configured with Protect TrackID.

SiteID should be available as suggested "SitesManager.getHashedID".

@joubertredrat , request you to prioritize this.

The main purpose or the use-case any one would look for is getting the Protect TrackID for a site that is dynamically added using "SitesManager.addSite". It could be an API that would add the site and return the hashed trackID, like "SitesManager.addSiteGetHashedID"

Thanks a lot.

siva538 avatar Nov 14 '18 11:11 siva538

Hi @Acen and @siva538, sorry for a big delay in my response.

Now the plugin have support to API request by ProtectTrackID.getHashedID method, below an example of request to get hashed id.

Request example

curl --request GET \
  --url 'http://matomo.host/?module=API&method=ProtectTrackID.getHashedID&token_auth=my-numeric-token&idSite=1&format=JSON'

Response example

{
  "value": "pxE3v5LOJlPpjqDzkNPo"
}

joubertredrat avatar Dec 17 '22 00:12 joubertredrat