nystudio107 / craft-instantanalytics-ga4

Instant Analytics brings full Google GA4 server-side analytics support to your Twig templates and automatic Craft Commerce integration
Other
3 stars 4 forks source link

Mechanism to prevent a page view #3

Closed bossanova808 closed 1 year ago

bossanova808 commented 1 year ago

I am using Auto Send PageViews

This results in page views for things that I don't expect - e.g. e.g. mini templates

image

Is there a way (or could there be a way :) ) - to stop that from happening?

khalwat commented 1 year ago

Are these things being loaded via XHR? If so, yes, we should probably detect that and not send a page view for them.

If you mean a way in general to not automatically do a page view in certain templates, there is the config setting autoSendPageView to false but then you'd have to manually add the code:

    {% block analytics %}
        {% hook 'iaSendPageView' %}
    {% endblock %}

https://nystudio107.com/docs/instant-analytics-ga4/using.html#simple-page-tracking

...for the pages where you do want to send the page view (maybe add it into your layout or such).

khalwat commented 1 year ago

4.0.0-beta.2

Addressed in: https://github.com/nystudio107/craft-instantanalytics-ga4/commit/2382b4c1ea986d0f13a6a462ca12c0fa7ddf4a09

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-instantanalytics-ga4": "dev-develop-v4 as 4.0.0-beta.2”,

Then do a composer clear-cache && composer update

bossanova808 commented 1 year ago

These templates are little utilities that work both on page load, as an include, and are indeed refreshed via ajax on demand if need be (e.g. a shipping quote when the cart changes). So yep, pretty sure it's the ajax request triggering the extra page view as if you were somehow doing them for includes I'd be seeing thousands ;)

Thanks Andrew!