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

TypeError: can_be_triggered_on_page_type() missing 1 required positional argument: 'page_type' #25

Open
feliche93 opened this issue Apr 17, 2021 · 2 comments

Comments

@feliche93
Copy link

I am trying to use this new awesome features but get the following error: TypeError: can_be_triggered_on_page_type() missing 1 required positional argument: 'page_type'. Callback traces to here:

https://github.com/torchbox/wagtail-ab-testing/blob/449a237292d401dea4a9dfe0ee49381cf5a049b4/wagtail_ab_testing/views.py#L135

My wagtail_hooks.py looks like this:

from wagtail.core import hooks
from wagtail_ab_testing.events import BaseEvent

from .models import ProductDetailPage


class ExternalLinkClickEvent(BaseEvent):
    name = "External Link Click"

    def get_page_types(self):
        return [
            ProductDetailPage,
        ]


@hooks.register('register_ab_testing_event_types')
def register_external_link_click_event_type():
    return {
        'external-link-click': ExternalLinkClickEvent,
    }

In my models.py file, I was planning to use RoutablePageMixin with a custom route and javascript call on button click to trigger a request to the route to log any potential conversion. Not sure how the javascript part works yet or what the best solution would be?

class ProductDetailPage(MetadataPageMixin, RoutablePageMixin, Page):
    """
    A generic product detail page.
    """

    product_primary_cta_link = models.URLField(
        help_text='Link to docassemble interview',
        blank=True,
        null=True
    )

    # other Fields...


    @route(r'^external_link_clicked/$')
    def external_link_clicked(self, request, *args, **kwargs):
        """
        View function for tracking click to external link.
        """

        # Check if the user is trackable
        if request_is_trackable(request):
            # Check if the page is the goal of any running tests
            tests = AbTest.objects.filter(goal_event='external-link-click', goal_page=self, status=AbTest.STATUS_RUNNING)
            for test in tests:
                # Is the user a participant in this test?
                if f'wagtail-ab-testing_{test.id}_version' not in request.session:
                    continue

                # Has the user already completed the test?
                if f'wagtail-ab-testing_{test.id}_completed' in request.session:
                    continue

                # Log a conversion
                test.log_conversion(request.session[f'wagtail-ab-testing_{test.id}_version'])
                request.session[f'wagtail-ab-testing_{test.id}_completed'] = 'yes'
  

Any help would be very much appreciated! Thanks 🙏

@suxilog

This comment has been minimized.

@suxilog
Copy link
Contributor

suxilog commented Aug 13, 2021

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