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

[Bug]: All Events Get Tracked using initial URL #22

Open
4 tasks done
DominickMuniz opened this issue Mar 6, 2024 · 1 comment
Open
4 tasks done

[Bug]: All Events Get Tracked using initial URL #22

DominickMuniz opened this issue Mar 6, 2024 · 1 comment

Comments

@DominickMuniz
Copy link

What did you expect? 🧐

When looking at event data sent over to GA, all events appear to be marked with the wrong url (whichever url was the initial load).

***Note: for the url to replicate I provided 'Deepreef.net'. This is a Shopify Dev store and requires a password to enter, which is: dom

What actually happened? 😵‍💫

For example, say I trigger an 'AddToCart' on my product page, it gets tracked on GA from my Homepage url instead. I'd expect it to use the product page url instead.

When looking at my data, lets say events per page in GA4 -- I'd like to not have all of them appearing to occur on the homepage.

Perhaps there's more configuration required on my end, I'm just not sure where to start. Maybe this should be a second issue, but scoll events don't fire normally either.


Also, is there a reason this plugin by default sends a Virtual_Pageview event, rather than just naming it PageView? Having the difference messes up event tracking when looking at a period prior-to vs. after installing swup.

I'm worried there's a cascade of hidden tracking issues I haven't noticed. I'm loving Swup for animations, but not having an simple way to keep tracking consistent will make this app unusable.

Swup and plugin versions 📝

<script src="https://unpkg.com/swup@4"></script> <script src="https://unpkg.com/@swup/head-plugin@2"></script> <script src="https://unpkg.com/@swup/gtm-plugin@2"></script> <script src="https://unpkg.com/@swup/ga-plugin@2"></script> <script> const swup = new Swup({ containers: ["#MainContent"], plugins: [new SwupHeadPlugin(), new SwupGtmPlugin(), new SwupGaPlugin()], }); </script>

What browsers are you seeing the problem on? 🧭

Chrome

Relevant log output 🤓

No response

URL to minimal reproduction 🔗

deepreef.net

Checked all these? 📚

@daun
Copy link
Member

daun commented Mar 13, 2024

Not sure about the event urls. GTM might require some sort of manual url reset to be able to correctly track the page an event was triggered from.

That said, the plugin is exceedingly simple and rather easy to implement on your own. That's all there's to it:

swup.hooks.on('page:view', () => {
  window.dataLayer.push({
    event: 'VirtualPageview',
    virtualPageURL: window.location.pathname + window.location.search,
    virtualPageTitle: document.title
  })
}

I'd suggest taking this, removing the plugin, and adjusting it to suit your needs. Analytics can get tricky very fast, especially on ecommerce sites. Keeping control of the implementation is probably a net positive anyway.

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