Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually track custom/virtual pageviews #7548

Closed
joseariel opened this issue Mar 26, 2015 · 9 comments
Closed

Manually track custom/virtual pageviews #7548

joseariel opened this issue Mar 26, 2015 · 9 comments
Labels
answered For when a question was asked and we referred to forum or answered it.

Comments

@joseariel
Copy link

We're attempting to setup a custom implementation of the piwik tracking client (code) to allow us to track page transitions on a single-page jquery mobile app.

Our code looks like this so far and works but when pulling the reports throw the url below, we only get an aggregated count for the main (initial) url and not a breakdown of the different virtual pages:

<!-- Piwik -->
    var currentURL = function() {
        var title = jQuery(".ui-page-active .ui-title"),
            currentStage = null,
            trackedURL = null;

        if (title && title[0].innerText.length > 0) { currentStage = title[0].innerText; }

        if (currentStage != null && typeof(currentStage) != 'undefined') {
            trackedURL = window.location.protocol + "//" + window.location.host + window.location.pathname + "#" + currentStage.toLowerCase().replace(' ', '-') + "?" + window.location.search.substring(1);
        } else {
            trackedURL = window.location.href;
        }

        return trackedURL;
    };
var _paq = _paq || [];
  _paq.push(['setDocumentTitle', currentURL()]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//analytics.loanspq.com/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 98]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);

        jQuery(window).on("pageshow", function(event) {
            console.log( currentURL(), event );
            _paq.push(['trackPageView', currentURL()]);
        });
  })();
<!-- End Piwik Code -->

Reporting URL:

/?module=API&method=Actions.getPageUrls&idSite=98&period=day&date=2015-03-26&format=JSON&token_auth=...&expanded=1

Returns:

[
{
label: "vl",
nb_visits: 1,
nb_hits: 32,
sum_time_spent: 4010,
nb_hits_with_time_generation: 32,
min_time_generation: "0.245",
max_time_generation: "0.737",
entry_nb_visits: 1,
entry_nb_actions: 32,
entry_sum_visit_length: 2586,
entry_bounce_count: 0,
exit_nb_visits: 1,
avg_time_on_page: 4010,
bounce_rate: "0%",
exit_rate: "100%",
avg_time_generation: 0.599,
idsubdatatable: 9,
subtable: [
{
label: "/VehicleLoan.aspx?lenderref=LPQUniversity_test",
nb_visits: 1,
nb_uniq_visitors: 1,
nb_hits: 32,
sum_time_spent: 4010,
nb_hits_with_time_generation: "32",
min_time_generation: "0.245",
max_time_generation: "0.737",
entry_nb_uniq_visitors: "1",
entry_nb_visits: "1",
entry_nb_actions: "32",
entry_sum_visit_length: "2586",
entry_bounce_count: "0",
exit_nb_uniq_visitors: "1",
exit_nb_visits: "1",
avg_time_on_page: 4010,
bounce_rate: "0%",
exit_rate: "100%",
avg_time_generation: 0.599,
url: "https://domain.com/vl/VehicleLoan.aspx?lenderref=LPQUniversity_test"
}
]
}
]

Any insights into how to correct this issue are greatly appreciated.

@RMastop
Copy link
Contributor

RMastop commented Mar 26, 2015

Hi @joseariel, did you enable the option "Keep Page URL fragments when tracking Page URLs" in the site settings?
If not everything after the # will be removed.

@joseariel
Copy link
Author

Hi @RMastop, you are everywhere! : )

I don't have access to the site setting. I will ask the admin to see if this is an option, although this hasn't been the case in the past.

Could I work around this by using a -, / or . instead of the # ?

Thanks!

@RMastop
Copy link
Contributor

RMastop commented Mar 26, 2015

You would get strange looking URLs, but a / would work.

@joseariel
Copy link
Author

I'm running a few tests now.

Can you confirm that this is the correct way to track the pageview manually?:

_paq.push(['trackPageView', currentURL()]);

@joseariel
Copy link
Author

I ran the test and it did count the new visits using the following call but it still doesn't break it down by pages on the reports. I believe that I'm not using the correct params for the trackPageView call.

Call (in Browser):

_paq.push(['trackPageView', "https://domain.com/vl/VehicleLoan.aspx.vehicle-information?lenderref=LPQUniversity_test"]);

API call (Report):

/?module=API&method=Actions.getPageUrls&idSite=98&period=day&date=2015-03-26&format=JSON&token_auth=...&expanded=1

Returns:

label: "/VehicleLoan.aspx?lenderref=LPQUniversity_test",
nb_visits: 2,
nb_uniq_visitors: 1,
nb_hits: 66,

The count went up from 32 to 66 but it only returns a single page with all pageviews aggregated.

Do you have any suggestions on how to get a breakdown of the different pages tracked?

@RMastop
Copy link
Contributor

RMastop commented Mar 26, 2015

In the first example you used _paq.push(['trackPageView', "https://domain.com/vl/VehicleLoan.aspx.vehicle-information?lenderref=LPQUniversity_test#pagetitlevalue"]);

In the second example you use _paq.push(['trackPageView', "https://domain.com/vl/VehicleLoan.aspx.vehicle-information?lenderref=LPQUniversity_test"]);

You omit the titlevalue in the last call. Is that a mistake or was it on purpose?

My solution would be
_paq.push(['trackPageView', "https://domain.com/vl/VehicleLoan.aspx.vehicle-information?lenderref=LPQUniversity_test/titlevalue"]);
That would create the extra page urls. For every unique combination of url / titlevalue a new page.

That is what I understood in your initial question.

@joseariel
Copy link
Author

I believe that the omission that you are referring to was simply a typo.

I like your suggested solution, I'm testing it now to see if the report reflects that pages broken down as you suggest.

I'll be back with an update. Thanks @RMastop

@joseariel
Copy link
Author

Hi @RMastop, I think the issue I'm hitting doesn't have to do with the tracking client.

I think it has to do with the Reporting API. I went to check the reports through the UI Dashboard and found that everything I had done was properly recorded under the 'Page Titles' section, even when I was using the # tag for the URL identifier.

But the issue is that what I really need to do is not customize the page title but rather the actual Page URL.

Do you know how to switch from tracking the page title to tracking a custom page url using _paq.push(['trackPageView'])?

I've attached screenshots.

screen shot 2015-03-26 at 4 48 18 pm

screen shot 2015-03-26 at 4 51 08 pm

@mattab
Copy link
Member

mattab commented Apr 8, 2015

Hi @joseariel

to set the Page URL use the method setPageUrl just before trackPageView - this should track the overriden URL for this page view. Feel free to re-open if you think there is a bug in Piwik

@mattab mattab closed this as completed Apr 8, 2015
@mattab mattab added the answered For when a question was asked and we referred to forum or answered it. label Apr 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it.
Projects
None yet
Development

No branches or pull requests

3 participants