electerious / Ackee

Self-hosted, Node.js based analytics tool for those who care about privacy.
https://ackee.electerious.com
MIT License
4.2k stars 351 forks source link

Ackee event tracking fails with "TypeError: instance.action is not a function". #326

Closed tomikaka22 closed 2 years ago

tomikaka22 commented 2 years ago

🐞 Describe the bug

When I try to track an event with Ackee, it fails with "TypeError: instance.action is not a function" error.

📚 To Reproduce

If the user accepts detailed tracking I set a local storage item. Here is my code:

        <script src="./ackee-tracker.min.js"></script>
        <script>
        if (localStorage.getItem('tracking') == 'on') {
            const instance = ackeeTracker.create('https://ackee.my.domain', {
                    detailed: true
            }).record('2f322116-45h7-481c-1477-542f42e92061')
        }
        else {
            const instance = ackeeTracker.create('https://ackee.my.domain', {
                detailed: false
            }).record('2f322116-45h7-481c-1477-542f42e92061')

            instance.action('5j899334-9l3c-43h1-944a-fdd6701f8231', { key: 'Click', value: 1 })
        }
        </script>

💡 Expected behavior

Ackee adds 1 click to the event I've set up.

⚙️ Environment

📋 Additional context

Love the app btw!

electerious commented 2 years ago

The problem is that you're saving the response of the .record function in the instance var, not the instance itself. Try to save the instance first and then call the record and action function separately.

const instance = ackeeTracker.create('https://ackee.my.domain', {
    detailed: true
})

instance.record('2f322116-45h7-481c-1477-542f42e92061')
instance.action('5j899334-9l3c-43h1-944a-fdd6701f8231', { key: 'Click', value: 1 })