File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -107,8 +107,17 @@ public function piwikCode()
107107 private function addDefaultApiCalls ()
108108 {
109109 $ this ->paqs [] = ['enableLinkTracking ' ];
110-
111- foreach ($ this ->paqs as $ paq ) {
110+ $ manuallyAddedTrackPageView = null ;
111+ foreach ($ this ->paqs as $ i => $ paq ) {
112+ if ('trackPageView ' === $ paq [0 ]) {
113+ /*
114+ * It is recommended to "trackPageView" e.g. after setDocumentTitle.
115+ * See https://matomo.org/faq/how-to/how-do-i-set-a-custom-page-title-using-the-matomo-javascript-title/
116+ * So, let's rearrange the paqs
117+ */
118+ $ manuallyAddedTrackPageView = $ paq ;
119+ unset($ this ->paqs [$ i ]);
120+ }
112121 if ('trackSiteSearch ' === $ paq [0 ]) {
113122 /*
114123 * It is recommended *not* to "trackPageView" for "trackSiteSearch" pages.
@@ -118,7 +127,10 @@ private function addDefaultApiCalls()
118127 return ; // Do not add 'trackPageView'
119128 }
120129 }
121-
122- $ this ->paqs [] = ['trackPageView ' ];
130+ if (null !== $ manuallyAddedTrackPageView ) {
131+ $ this ->paqs [] = $ manuallyAddedTrackPageView ; // move manually added 'trackPageView' to the end
132+ } else {
133+ $ this ->paqs [] = ['trackPageView ' ];
134+ }
123135 }
124136}
You can’t perform that action at this time.
0 commit comments