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 tracking and AMP compatibility #110

Closed
Zodiac1978 opened this issue Oct 3, 2018 · 3 comments
Closed

JS tracking and AMP compatibility #110

Zodiac1978 opened this issue Oct 3, 2018 · 3 comments

Comments

@Zodiac1978
Copy link
Member

I stumbled upon this blog post about making Statify AMP compatible:
https://die-computermaler.de/statify-und-amp-accelerated-mobile-pages/

Eigener JavaScript-Code kann in AMP-Seiten spezifikationsbedingt nur mit erheblichen Verrenkungen ausgeführt werden und wird vom „Sanitizer“ des WordPress-AMP-Plugins (https://de.wordpress.org/plugins/amp/) dementsprechend sinnvollerweise herausgefiltert. Das Ärgerliche daran ist: Sowohl die mobile Suche von Google als auch die mobilen Twitter-Apps verweisen i. d. R. auf die AMP-Version der Seite – mobile Aufrufe von Twitter-App-Nutzern oder Aufrufe über die mobile Google-Suche bleiben also für Statify größtenteils unsichtbar.

Glücklicherweise ist dieses Problem lösbar: Die AMP-Spezifikation verfügt über das Tag , dem per JSON-„Script“ Anweisungen übergeben werden können, welche URL bei welchem Event zu Tracking-Zwecken aufgerufen werden soll. Das WordPress-AMP-Plugin verfügt zudem unter „AMP“ → „Analytics“ über eine eigene Konfigurationsseite für eben diese JSON-Datei. Hinterlegt man dort eine entsprechende Konfiguration, kann man bei jedem Aufruf einer AMP-Seite die selbe Tracking-URL ansprechen lassen, der für „normale“ Seiten vom Statify-Tracking-Script aufgerufen wird:

So we could try to do this programmatically (automatic or per option) or we can add this to our documentation.

@felixarntz
Copy link

I haven't looked at this any closer so far than reading the documentation in https://github.com/ampproject/docs/blob/master/content/docs/analytics/analytics-vendors.md, so I can't really be of any help here unfortunately. This generally is the right approach, of course I'm not aware about the specific details that Statify would require. However the article seems to give a good headstart.

Regarding the implementation, it would probably be best if Statify supported this out-of-the-box, without requiring manual addition of the complicated information via the AMP plugin. The plugin might as well check if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) and then output the necessary AMP-HTML with the JSON data automatically (instead of the default script it outputs). That would be more comfortable for the users. I consider the current textarea that the AMP plugin provides just a non-user-friendly fallback solution for Analytics providers and plugins that don't support it themselves.

@Zodiac1978
Copy link
Member Author

@felixarntz Thanks for your feedback! :)

patrickrobrecht added a commit that referenced this issue Apr 21, 2020
* Update class-statify-frontend.php

* Add filter for AMP analytics

* Update class-statify.php

* minor code style corrections (no semantics changed)

* do not append AMP analytics script if no JS tracking is used

* do not specity "type" attribute for AMP analytics script

There is no valid analytics vendor "statify" and we trigger a local
endpoint. To prevent AMP analtics from calling a vendor-endpoint with
404 result in this case, the type attribute is left empty.

* docs++

* adjust AMP analytics config to issue a POST request for WP-AJAX

Co-authored-by: Stefan Kalscheuer <[email protected]>
Co-authored-by: Torsten Landsiedel <[email protected]>
Co-authored-by: Patrick Robrecht <[email protected]>
@patrickrobrecht
Copy link
Member

Implemented in #116, bugfixed in #182.

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

No branches or pull requests

3 participants