tyxla / Gravity-Forms-Multiple-Form-Instances

Allows multiple instances of the same form to be run on a single page when using AJAX.
GNU General Public License v2.0
37 stars 23 forks source link

View count #2

Closed cfxd closed 9 years ago

cfxd commented 9 years ago

Any plans to make sure the view count for each form is not counted multiple times? That would really be awesome!

tyxla commented 9 years ago

Nice one, thanks for that.

But, actually, for me it makes sense that each form view is counted separately.

For example, if the same form is displayed twice on the same page, that form is basically displayed (therefore viewed) twice, so increasing the counter twice makes sense. This way the view counter actually reflects the number of times that a form has been displayed. And if we count the two form views as one, that would contradict the above statement - the form would be displayed twice, but viewed only once? This does not make any sense at all.

I assume the functionality you suggest would make sense in certain specific cases, but I believe it is not acceptable in the default behavior. I believe that even adding a setting for enabling that functionality would be confusing and unrelated with the main plugin idea. If necessary, this functionality can (and should) be implemented independently of this plugin - we don't plan to implement it.

If you need any guidance in terms of how to implement this in your project, please let me know. Since I spent some time digging in the GravityForms code about your inquiry, I'd gladly share a couple of possible implementations.

cfxd commented 9 years ago

That definitely makes sense.

I guess the use case I envision is if a design absolutely cannot be accomplished responsively without two instances of the same form. Say for example, a newsletter subscription form on smaller devices that appears in a site footer, but on larger/desktop devices it appears in the header. If each form is being hidden at the appropriate breakpoint using CSS then it seems each page view, regardless of the browser width, will add two views to the form. That could lead to inaccurate conversion rates too.

I'm not sure there is an easy solution to the problem but I'd love to hear what you uncovered because I did some quick searching and couldn't figure out much.

Thanks again for the nifty, lightweight plugin. I was surprised to find that this kind of functionality isn't included in GF core, especially when plenty other poorer quality plugins do allow repeating the same form multiple times on a page.

tyxla commented 9 years ago

Your use case sounds plausible indeed.

Regarding the solution to fix this:

Gravity Forms has a gform_disable_view_counter_{$form_id} filter, which allows you to control whether the view counter of a particular form is disabled (false by default). So the idea here is: create a function and hook it to the gform_get_form_filter filter (which is also used in my plugin, later than the above hook). And in that function, add a filter function to disable the form view count for that form ID.

The above solution would programatically look like this (untested):

add_filter('gform_get_form_filter', 'l2l_gform_get_form_filter', 10, 2);
function l2l_gform_get_form_filter($form_string, $form) {
    add_filter('gform_disable_view_counter_' . $form['id'], '__return_true');
    return $form_string;
}

Please, note that the form views are never counted when a logged in administrator is viewing them, so when testing that you might want to view the forms as a logged out user.

I'm glad you find the plugin useful - thanks. You can feel free to rate the plugin at the WordPress plugins page, as well as watch & star the plugin here for hot updates.