We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17016
    • 138 Posts
    I want to start a snippet when a user clicks on a certain link. For this I added this code:

    <a onclick="[[!mysnippet]]" href="[[~1]]">LINK</a>


    Unfortunately the snippets now fires already when the page is loading even when not clicking on the link. I guess this is because "onclick" needs a javascript-call. Is there any javascript-code which could inserted here to load/start the snippet not before clicking on the link? Does anybody know this?

    Letti
      • 33968
      • 863 Posts
      The only way I can think of to do that is by using ajax. What does your snippet do?
        • 17016
        • 138 Posts
        Hi Lucas,
        the Snippet is a part of a A/B-Testing-Tool I developed for MODx. This snippet counts the conversions (for example how many visitors of the page-variation B click on the link) including a check if the visitor already has converted/clicked on the link before and which variation the visitor is assigned to. Afterwards the snippet will saves a value to a variable of the resource where the A/B-Test is located.
          • 4172
          • 5,888 Posts
          why not running the snippet on the landing-page?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 17016
            • 138 Posts
            That is possible, too. But if you reach the landing-page by a different way (for example by a direct type in or a deep link from another website) this can result in wrong conversion-rates. Beside this we need the onclick-way for measuring conversions which are defined by downloads of pdfs. Do you have any idea how to solve this by the onclick-method?

            Letti
              • 4172
              • 5,888 Posts
              you can put your snippet on an extra resource and send an ajax-request to this resource by "onclick"
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 17016
                • 138 Posts
                Thanks for your answer. Can you tell me how the ajax-request should look like? I am not sure how to do this. Would be great.

                Thanks a lot!
                Letti