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

JS Code Displayed Twice #13

Open
LiamW opened this issue Nov 8, 2023 · 4 comments
Open

JS Code Displayed Twice #13

LiamW opened this issue Nov 8, 2023 · 4 comments

Comments

@LiamW
Copy link

LiamW commented Nov 8, 2023

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.

Screenshot 2023-10-25 at 9 28 21 AM

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.

Screenshot 2023-11-08 at 12 40 30 PM
@axllent
Copy link
Owner

axllent commented Nov 9, 2023

Hi @LiamW. This is interesting, something I haven't encountered before. It looks to me like you possibly have a $genAnalyticsCodeTrackingCode in your Page.ss file? If so, then this should be removed as that function (which is the one that inserts both the header and footer code) is run automatically via Controller::doInit() (specifically onAfterInit() invoked via Controller::doInit()).

As for the phone click tracking in GA4 - I hate to admit this but I haven't a clue since it switched. It is one of these things I've been meaning to get to but have never had the time for. This used to work flawlessly in the previous GA, but in GA4 one does have to set up something to "store" (or at least view) this. I would greatly appreciate if you could document this for me please - assuming you find the solution. I know that link clicking in general is automatically tracked in GA4 provided one has turned on that option, so that may make this a redundant feature if it is already covered by GA4.

@LiamW
Copy link
Author

LiamW commented Nov 9, 2023

I don't have any code on any templates involving this module. It's just out of the box. I've used this module a few times pre GA4 code and it worked fine. This is first time installing this module using the new GA4 code. It's been running for about a month and constantly doing this.

I'm not a developer. Here is my composer list in case it's something else conflicting with it.


        "silverstripe/recipe-plugin": "^1.2",
        "silverstripe/recipe-cms": "4.13.*",
        "silverstripe/login-forms": "4.*",
        "silverstripe/blog": "^3.0",
        "silverstripe/redirectedurls": "^2.2",
        "silverstripe/userforms": "^5.15",
        "kinglozzer/metatitle": "^2.0",
        "bummzack/sortablefile": "^2.0",
        "undefinedoffset/silverstripe-nocaptcha": "^2.3",
        "axllent/silverstripe-version-truncator": "^3.0",
        "wilr/silverstripe-googlesitemaps": "^2.2",
        "heyday/silverstripe-cacheinclude": "~5.0",
        "symbiote/silverstripe-gridfieldextensions": "^3.0",
        "dnadesign/silverstripe-elemental": "^4",
        "dynamic/silverstripe-elemental-baseobject": "^3.0",
        "dynamic/silverstripe-elemental-gallery": "^3.0@alpha",
        "dnadesign/silverstripe-elemental-userforms": "^3.3",
        "dnadesign/silverstripe-elemental-virtual": "^1",
        "dynamic/silverstripe-elemental-features": "^3.0",
        "axllent/silverstripe-analytics-js": "^4.0"

I think the code for tracking email/phone clicks are redundant now. With GA4 I've only used it with GTAG so I'm new to trying to track these clicks without it but when I was researching yesterday, I don't think it's needed anymore. Outbound link tracking is a default turn on option in GA4, so that's for sure not needed.

I found a short video explaining how to setup the event. https://www.youtube.com/watch?v=DpN4Hxe9IoE

@LiamW
Copy link
Author

LiamW commented Nov 9, 2023

As I've mentioned before, I've had this running for a month. I did not find the tracking tel and mailto links worked out of the box but I also didn't get around to manually setting it up on the GA4 side. I think the 404 tracking did work though as I do see those events, but not sure if that's default GA4 stuff. I don't think it is.

With that said, now that I've confirmed with you it's probably redundant and not needed, I'll probably uninstall this module as I was only using it in the past to track those clicks without having to use GTM as it really did work perfectly and is all I needed since I build marketing lead gen sites.

But now that things have changed, I might as well just embed the GA4 tracking code on the template.

So we don't have to spend a lot of time on this bug, but just a heads up it is a thing I guess.

@axllent
Copy link
Owner

axllent commented Nov 10, 2023

Thanks @LiamW, that is very useful and I really appreciate your input. I really haven't a clue why your code is being inserted twice, but given the fact that that it is run via onAfterInit() I suspect that one of those modules is manually calling that or also extending with that (incorrectly). I've run into this in the past with one of my own modules - rookie mistake, and not the fault of this module. There is however something I can do to prevent it injecting multiple times is called more than once.

Anyway, it appears GA4 can track all of these events manually now, meaning I should probably remove that manual tracking code altogether. I just tried to set this up on a test website with just the raw GA tracking code (ie: not via this module) following that video (really helpful, thanks), but alas, no email address tracking - sigh, oh well, I give up today.... I really think that GA4 has become far too complicated for most and this has really turned me against it. I also really do not plan on using Tag Manager so I'll come back to this at some point and (try) to persevere and get event tracking working in GA4 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants