duracelltomi / gtm4wp

Google Tag Manager plugin for WordPress
https://gtm4wp.com/
GNU General Public License v3.0
147 stars 96 forks source link

Feature: Word Count as a Data Layer Variable #56

Open ju1 opened 6 years ago

ju1 commented 6 years ago

It would be awesome to have the word count in the data layer when the page loads. Even more useful could be "Range of word count", possible values:

I would later pass these values as custom dimensions with pageview hits and then see which word count is the most correlating with content engagement, newsletter signups, etc.

vincentkoc commented 6 years ago

@ju1 might look into this, will see how it affects speed/rendering first. Also in regards to "ranges" this should be handled in the analytics platform (via calculated dimensions) or the tag manager to keep it clean, as ranges might differ for users needs.

ju1 commented 6 years ago

Thanks for the update. And that's a good idea to calculate ranges on our own.

tijevlam commented 6 years ago

Wouldn't it make more sense to calculate the word count directly in GTM? Thats easy with a simple javascript and gives you a lot of control on which sections of content you would like to include in the wordcount.

duracelltomi commented 6 years ago

@tijevlam the main purpose of this plugin is to add features which would normally need JS codes inside your GTM container. Having the word count was requested many times I just do not see whether this can be implemented without affecting page load performance on sites with heavy traffic.

But since we are talking about an option that could be disabled on those sites, I would be happy to have this in the plugin. My guess is that there must be some ready made codes on the net which we could include (also legally) instead of writing our own code.

vincentkoc commented 6 years ago

@duracelltomi i have a simple working solution that uses the WP_Query loop. Will add in once the other PR's are cleared so we don't have too many conflicting changes. If there is no harm on performance we can add it in, if there is we can decide if to include with any warnings.

duracelltomi commented 6 years ago

Thanks! Two PRs still needs some change as far as I can see but both are very close to be merged i guess :-)

In my experience adding a warning is always the best way: WordPress can be running on various servers with lots of plugins, there will be always cases where such an algorithm will degrade performance.

tijevlam commented 6 years ago

@duracelltomi i see your purpose with the plugin. I'm mostly fan of the option to include variables that are available only or more easily on the server side of things.

I agree it would come in handy when the wordcount would be available straight from this plugin. However, I don't think this should have a significant effect on performance.

I'm eager to see how your solution works @koconder. I've seen some specific wordcount plugins for WP, they all save the wordcount in a new table (or column) in the posts-table. Which would bea great effect solution performancewise i'd say, but would mean a lot of extra implications for this plugin.

Adding to the wordcount, from a analytist-perspective: I'd suggest we also add imageCount and videoCount. I've made reports and analysis in the past that exposed a real cohersion between reads, scroll depths and number of images/media.

duracelltomi commented 6 years ago

having the word count cached in post_meta would be a good idea to minimize impact on performance - but we need to prepare a code that will store this for already existing posts - I guess this can be done while a post is being viewed by a visitor as this would only affect this one page load perhaps

duracelltomi commented 5 years ago

I wonder if this can be done just by using str_word_count()

Perhaps a cleaning would be necessary first: https://plugins.trac.wordpress.org/browser/wp-word-count/trunk/includes/class-wpwc-functions.php#L56

I wonder if apply_filters() with 'the_content' would be also needed before counting the words?

duracelltomi commented 5 years ago

... or we could just use wp-admin/js/word-count.js

camassey commented 4 years ago

Hi @duracelltomi - am I right in thinking this hasn't been merge / released yet? Is there (currently) any plan to?

duracelltomi commented 4 years ago

No, it has been not merged yet, I want to finish the next version shortly.

Due to covid and being a bit more tired at work, I was adding more vacation and time with my family but I intend to speed up things in the coming weeks

vincentkoc commented 4 years ago

@duracelltomi my original suggestion was to bake in support for 3rd party word count plugins, and just read data via post_meta into dataLayer which would be easier to support and maintain. As some sites/themes/plugins could have differences in word count and would be better to focus on pulling in data rather than trying to calculate ourselves.

Paktas commented 1 year ago

Each plugin has a slightly different way of counting words. If you embedd content - some fail to recognise HTML, some do, some regard fullstop (.) as word delimiter when it's just a decimal. Would be best to use some methodology that is at the core of WP to nativelly count words.