Like https://drupal.org/node/613648 (http://drupalcode.org/project/google_analytics.git/commitdiff/f976a931a2...) - but for search_api.
The attached patch adds an admin-section if search_api is enabled that allows the user to enable the functionallity and optionally specify which paths should be trigger the reporting.
Upon hitting the search-page a custom-url is generated which contains the search-terms in the form GA expects, and to make custom reporting even easier a ZeroResults event is also reported.
The patch was made against 7.x-1.x and does not apply on 2.x, but as far as I can see it does not clash with any functionallity in 2.x so it should be possible to port it to 2.x as well.
Comment | File | Size | Author |
---|---|---|---|
#22 | search_api_tracking-2183307-22.patch | 10.56 KB | fengtan |
#18 | search_api_tracking-2183307-18.patch | 9.34 KB | brunodbo |
#16 | interdiff-11-16.txt | 1.32 KB | kekkis |
#16 | site_search_tracking-2183307-16-D7.patch | 5.99 KB | kekkis |
| |||
#8 | googleanalytics-search_api-2183307-8-D7-do-not-test.patch | 6.21 KB | arnested |
Comments
Comment #1
danquah CreditAttribution: danquah commentedComment #2
danquah CreditAttribution: danquah commentedComment #3
jaydub CreditAttribution: jaydub commentedWe have need for this as well. I've taken the patch against 7.1 branch and applied with minor changes to latest dev version of 7.2 branch. Am pushing out on our end to test so will post back in here with results but for now I've attached the patch.
Unfortunately the patch probably won't test successfully in this ticket unless I change the issue version to 7.2 which I didn't want to do per the original poster's patch but can set to 7.2 to test later or maybe a new ticket would be needed.
Comment #5
hass CreditAttribution: hass commentedComment #6
weri CreditAttribution: weri commentedI could apply patch #3 to 7.2 without problems and it works as expected. I hope this could be added to 7.2 soon.
Comment #7
Agileware CreditAttribution: Agileware commentedUpdated patch which includes tracking for search API queries, exposed views filters and paths. Required if the website is using Search API module.
Comment #8
arnested CreditAttribution: arnested at Reload commentedThe patch (all versions of it) is vulnerable to XSS attacks because the search query string is used directly in the output.
I wrapped it in
check_plain()
, rerolled it against 7.x-2.x, and fixed two minor code style issues in the added code.Btw. The original patch assumed the search query to be the last element of the path whereas the new patch assumes the search query to be stored in a query parameter. That change actually broke the use case me and @danquah have because the site the patch was written for uses serch pages with an URL structure like
/search/my%20search%20term
.It would probably be better to identify the search query string from the
SearchApiQuery
object. But from Search APIs point of view there is no one search string. There could be several searches on one page (we actually have three) and the search could be build up from facets etc. So I will not change that part now :-)Comment #9
hass CreditAttribution: hass commentedCheck_plain is incorrect. It is JS abd this require drupal_json_encode(). This version of code looks fully untested. It cannot work as 2.x is universal analytics and I see ga.js code. An code style is not like core, too.
Comment #10
hass CreditAttribution: hass commentedcode style invalid
code style invalid
ga.js and not analytics.js. Patch has never tested!
Comment #11
joelpittetRegarding #10.3 I've removed that, if someone wants to implement that later, the docs are here https://developers.google.com/analytics/devguides/collection/analyticsjs...
And I hope I fixed the coding standards and removed the check_plain.
Moving to 7.x-2.x to test, will move back after.
Comment #12
joelpittetComment #13
jelo CreditAttribution: jelo commentedPotential duplicate of https://www.drupal.org/node/934076 (see https://www.drupal.org/node/1694622 also)...
Comment #14
joelpittetOne thing that caught me a couple of times with this is that "Search result query string" is set to 's' and in google analytics it's set to 's' but it wasn't tracking because we are hardcoding it to 'search' as the query string key.
Probably should leave it as
?
Comment #15
joelpittetAKA
Thoughts?
Comment #16
kekkisRerolled the D7 patch and added @joelpittet's suggested fix for the
$search_query_key
.Comment #17
imperator_99 CreditAttribution: imperator_99 commentedHi,
Is there a D8 version of the patch? The version is 8.2x-dev but I can only see what looks to be D7 patches.
Cheers,
Jesse.
Comment #18
brunodboHere's a D8 version of the patch in #16.
Comment #19
rovoSince you are able to login to Google Analytics and set the Query Parameters used for your site's search, is this feature really needed in the module? Does enabling this feature via the patch, enhance search query tracking beyond what is done when the correct query parameters are added directly to your Google Analytics View settings?
Greatly appreciate any insight and guidance on this.
Thank you.
Comment #20
japerryComment #21
DamienMcKennaThe patch needs to be reworked, in particular the changes to google_analytics.module no longer apply.
Comment #22
fengtanRe-rolled against 4.x -- one of the services comes from search_api which is not a module dependency and as a result cannot be unconditionnally injected, so for now it is called statically: