Fraze Jr.
Fraze Jr.

Reputation: 143

Syntax error on a onclick event

I want to transfer some informations to my Google Analytics account, to get informations about my site. But I have one problem. I always get in the console:

(index):2513 Uncaught SyntaxError: missing ) after argument list

This is my onclick=".." line:

<a onclick="googleAL(https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp, South Park The Fractured But Whole);" href="https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp" title="South Park The Fractured But Whole" class="btn btn-buy btn-sm btn-block" rel="nofollow" target="_blank">Kaufen*</a>

But the straing thing is that it is working with another function:

<a onclick="fbPixels();" href="https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp" title="South Park The Fractured But Whole" class="btn btn-buy btn-sm btn-block" rel="nofollow" target="_blank">Kaufen*</a>

So I think, the reason why it is not working must be the googleAL function:

onclick="googleAL(https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp, South Park The Fractured But Whole);"

But where is my error? - Why throws this line a error? I don't se the error...

The function doesn't even gets called... I know that, because I do not get a alert. Where is the error in this line?

The googleAL function looks like:

<script>
        function googleAL(url, title) {
            alert("Hello" . url, title);
            ga('send', 'event', {
                    eventCategory: 'lead',
                    eventAction: title,
                    eventLabel: url
            });
        }
</script>

Greetings and Thank You!

Upvotes: 0

Views: 488

Answers (2)

Cyril Beeckman
Cyril Beeckman

Reputation: 1278

Try this with correct syntax.

You should enclose with quotes, but now there are string. If you want to change type of data, change into your function in javascript.

<a onclick="googleAL('https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp', 'South Park The Fractured But Whole');" href="https://www.gamesdeal.com/south-park-the-fractured-but-whole-pc.html?___store=english?a_aid=gmkshp" title="South Park The Fractured But Whole" class="btn btn-buy btn-sm btn-block" rel="nofollow" target="_blank">Kaufen*</a>

Upvotes: 0

David
David

Reputation: 218847

String values need to be enclosed in quotes.

So instead of this:

googleAL(http://...)

You'd want this:

googleAL('http://...')

Each argument would be its own string in this case, too:

googleAL('http://...', 'South Park...')

Upvotes: 3

Related Questions