axllent / silverstripe-analytics-js Goto Github PK
View Code? Open in Web Editor NEWExtension to add Google Universal Analytics (gtag.js) tracking code to Silverstripe
License: MIT License
Extension to add Google Universal Analytics (gtag.js) tracking code to Silverstripe
License: MIT License
It looks like Google is starting to push users over to gtag.js instead of analytics.js, would you be open to a pull request to move this module over to it as well or would you rather we (WBG) fork the module and brand it as a new module under our org?
When running the RebuildStaticCacheTask that is part of the silverstripe-staticpublisher, the $ga_trackers
variable accumulates events in an unwanted fashion. The task builds for example the following set of pages:
FilesystemPublisher: Publishing to
* Publishing page 1/16: /silverstripe/
* Publishing page 2/16: /silverstripe/de/
* Publishing page 3/16: /silverstripe/de/about-us/
* Publishing page 4/16: /silverstripe/de/contact-us/
* Publishing page 5/16: /silverstripe/de/page-not-found/
* Publishing page 6/16: /silverstripe/de/server-error/
* Publishing page 7/16: /silverstripe/en/about-us/
* Publishing page 8/16: /silverstripe/en/contact-us/
* Publishing page 9/16: /silverstripe/en/page-not-found/
* Publishing page 10/16: /silverstripe/en/server-error/
* Publishing page 11/16: /silverstripe/fr/
* Publishing page 12/16: /silverstripe/fr/about-us/
* Publishing page 13/16: /silverstripe/fr/contact-us/
* Publishing page 14/16: /silverstripe/fr/page-not-found/
* Publishing page 15/16: /silverstripe/fr/server-error/
For the first page everything is ok and
ga("create","UA-DEV-1","auto");ga("send","pageview");
is inserted. The second page gets
ga("create","UA-DEV-1","auto");ga("send","pageview");ga("send","pageview");
the third
ga("create","UA-DEV-1","auto");ga("send","pageview");ga("send","pageview");ga("send","pageview")
Until finally
ga("create","UA-DEV-1","auto");ga("send","pageview");ga("send","pageview");ga("send","pageview");ga("send","pageview");ga("send","event","404 Page Not Found",document.location.pathname+document.location.search,document.referrer);ga("send","event","500 Page Error",document.location.pathname+document.location.search,document.referrer);ga("send","pageview");ga("send","pageview");ga("send","event","404 Page Not Found",document.location.pathname+document.location.search,document.referrer);ga("send","event","500 Page Error",document.location.pathname+document.location.search,document.referrer);ga("send","pageview");ga("send","pageview");ga("send","pageview");ga("send","event","404 Page Not Found",document.location.pathname+document.location.search,document.referrer);ga("send","event","500 Page Error",document.location.pathname+document.location.search,document.referrer);
is inserted into the last page.
I'm running latest SS4 with the latest version of this module.
The JS code in both the head and body is being displayed twice as seen in the screenshot for the body code.
And just want to confirm the best way to setup the event for email and phone click tracking? I've only used this module with GA, new to GA4 and this module.
Hey, just came across your module, very useful for the newer universal analytics however I have found that when you module is listed on the addons website the .js part causes some problems as I beleive it gets interpreted as a javascript file rather than a listing on the addons site.
Might pay to revise this and resubmit to packagist with a more meaningful name (perhaps include an indication that it is the universal tracking). For example: axllent/silverstripe-universalanalytics or something to that effect.
Hello @axllent
thanks for this neat library! I was wondering if there is an option to avoid tracking for signed in users?
Cheers,
Peter
When running the RebuildStaticCacheTask
that is part of https://github.com/silverstripe-labs/silverstripe-staticpublisher, the first page is published without error, but all subsequent throw a GaTracker::add_ga(): Default Tracker already set, please use name
user warning.
Trace
trigger_error(GaTracker::add_ga(): Default Tracker already set, please use name,512)
AnalyticsJS.php:98
AnalyticsJS->parseGoogleUniversalAnalyticsConfigs()
AnalyticsJS.php:58
AnalyticsJS->injectGoogleUniversalAnalyticsCode()
AnalyticsJS.php:49
AnalyticsJS->onAfterInit(,,,,,,)
Object.php:998
Object->extend(onAfterInit)
Controller.php:145
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:197
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:76
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
FluentRootURLController.php:97
FluentRootURLController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:360
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:281
Director::test(http://localhost/~nbennett/neptun_web/de/)
FilesystemPublisher.php:231
FilesystemPublisher->publishPages(Array,,,,,,)
Object.php:998
Object->extend(publishPages,Array)
RebuildStaticCacheTask.php:107
RebuildStaticCacheTask->rebuildCache(Array,1)
RebuildStaticCacheTask.php:26
RebuildStaticCacheTask->run(SS_HTTPRequest)
TaskRunner.php:84
TaskRunner->runTask(SS_HTTPRequest)
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,runTask)
Controller.php:194
Controller->handleAction(SS_HTTPRequest,runTask)
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel)
Director.php:360
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:152
Director::direct(/dev/tasks/RebuildStaticCacheTask,DataModel)
main.php:189
require_once(/Users/nbennett/Sites/neptun_web/framework/main.php)
main.php:39
skipCache()
main.php:128
Despite the user warning, the resulting HTML is perfectly usable and Google Analytics seems to work fine.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.