Git Product home page Git Product logo

Comments (5)

RobertJoonas avatar RobertJoonas commented on August 16, 2024 1

No worries! Will your <div class="child"> be only child of <div class="parent" ... > too? In that case you can do:

var form = wrapper.children[0].children[0]

instead of:

var form = wrapper.children[0]

from docs.

RobertJoonas avatar RobertJoonas commented on August 16, 2024

Hi @Waleedov!

The following code should work if the <form> element is the only child of the wrapper <div>:

<div data-analytics='"My Event Without Properties"'>
    <form>
        <button type="submit">Send Message</button>
    </form>
</div>

<div data-analytics='"My Event",{"props":{"my_property":"some_value"}}'>
    <form>
        <button type="submit">Send Message</button>
    </form>
</div>

<script>
    let wrapperElements = document.querySelectorAll('div[data-analytics]')
    for (var i = 0; i < wrapperElements.length; i++) {
        let wrapper = wrapperElements[i]
        var form = wrapper.children[0]

        let attributes = wrapper.getAttribute('data-analytics').split(/,(.+)/);
        let eventName = JSON.parse(attributes[0])
        let eventOptions = JSON.parse(attributes[1] || '{}')
        eventOptions.callback = function() { form.submit() }

        form.addEventListener('submit', function(event) {
            event.preventDefault();
            setTimeout(eventOptions.callback, 5000);
            plausible(eventName, eventOptions)
        })
    }
</script>

Hope this helps!

from docs.

Waleedov avatar Waleedov commented on August 16, 2024

Thanks, to be exact, this is the structure:

<div class="parent" data-analytics='"My Event Without Properties"'>
  <div class="child">
      <form>
          <button type="submit">Send Message</button>
      </form>
  </div>
</div>

Can you please adjust the code? sorry I am very noob in JS.

from docs.

Waleedov avatar Waleedov commented on August 16, 2024

Thank you. Where can I ask for premium support? Someone to check my website, dashboard etc..?

from docs.

metmarkosaric avatar metmarkosaric commented on August 16, 2024

hi @Waleedov! you can reach our customer support here

from docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.