Problem/Motivation

Many sites use a form of hash-based navigation, to the point where it is often desirable to treat hash variants as unique pages for GA purposes. The URL submitted with a standard GA pageview does not include the URL fragment by default.

Proposed resolution

Allow GA module administrators to choose to include URL fragments in pageview logic. Provide a simple checkbox on the admin form. Reference this setting:

  1. Prior to writing the ga("send", "pageview") portion of the inline javascript generated in googleanalytics.module, and set the page value accordingly
  2. On any hashchange event captured in googleanalytics.js, and submit a pageview accordingly

Remaining tasks

  1. Review and test patch

User interface changes

Added checkbox to "Advanced Settings" section of admin form so that GA admins can choose to treat hash changes as pageviews and to include fragments in the page/path value submitted with each pageview.

API changes

None.

None known.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ndewhurst’s picture

Patch attached. I've tested this code locally (with admin option enabled/disabled) and am seeing the expected behavior in GA real-time content reports.

ndewhurst’s picture

Updating patch to remove unnecessary line.

hass’s picture

Status: Needs review » Needs work

There are bugs in translateable strings and D8 first.

ndewhurst’s picture

OK, thanks. I'll try to get my D8 install up to speed and take a stab at this when I get a chance. What are the translatable string bugs (just so I know where to look)? I can reformat the t() calls to not use a multi-line string argument.
PS - for doing D8 work, should I create a separate issue, or stay within this one and update the issue version accordingly?

hass’s picture

Multiline is not supported by potx extractor. No need for a extra D8 case.

hass’s picture

Issue summary: View changes

Updated issue summary.

hass’s picture

Fixed the bugs, added uninstall, added tests, corrected logic.

But I guess that the code in googleanalytics.js causes double trackings and collide with the rest of the tracking in these file. I have not tested this feature myself.

Status: Needs review » Needs work

The last submitted patch, 6: Issue-2092173-Optionally-Consider-URL-Fragments-Hash.patch, failed testing.

hass’s picture

Fixed one variable name.

hass’s picture

Suxxx EGit.

hass’s picture

Status: Needs work » Needs review

  • Commit 627c60d on 8.x-2.x by hass:
    Issue #2092173: Track changing URL fragments as pageviews
    

  • Commit 40fb781 on 7.x-2.x by hass:
    Issue #2092173: Track changing URL fragments as pageviews
    
hass’s picture

Status: Needs review » Fixed

  • Commit 0c7ee1a on 8.x-2.x by hass:
    Issue #2092173: Wrong variable for settings used.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.