Viewing 9 replies - 1 through 9 (of 9 total)
  • krmmalik

    (@krmmalik)

    Can this be used with the javascript hook?

    Currently i’m using “on_sent_ok” to push a pageview to Google Analytics for goal tracking but my goal URL on all pages is the same.

    Here is my code :

    on_sent_ok: "_gaq.push(['_trackPageview', '/ContactFormFilled']);"

    I could really do with passing the URL parameter in there if its do-able?

    Thread Starter skyer2000

    (@skyer2000)

    krmmalik

    (@krmmalik)

    Thanks for the link, but my implementation is already following those guidelines.

    The issues how i have is my contact form appears on multiple wordpress pages, and therefore the same URL is specified in the javascript action hook to be registered for the goal. What happens as a result of this, is that Google Analytics shows me an inflated number of conversions for my goals since all my goals have the same URL.

    I need to be able to push a different URL to GA for each page the contact form appears on. Obviously i could create a new form for each page, but its more work but if thats what i have to do then so be it.

    Thread Starter skyer2000

    (@skyer2000)

    I would try passing a $_GET variable on each page, with a unique URL (can be fake).

    So each form could be:

    https://mysite.com/form?url=/form/1
    https://mysite.com/contact?url=/form/2
    https://mysite.com/team?url=/form/3

    Using my plugin you can pass that variable into the form while the user fills it out:

    [getparam url]

    Then, if Contact Form 7 allows it, you can then pass [url] into on_sent_ok:

    on_sent_ok: “_gaq.push([‘_trackPageview’, ‘[url]’]);”

    I’m not sure if that would work, but maybe changing [url] to something like $_POST[‘url’] would?

    krmmalik

    (@krmmalik)

    OK – The last part of your solution i understand and is exactly what i am after, but would i have to manually setup the $_GET variable for each page, or will that be automatically populated due to the page’s own slug/url?

    It’d be really great if something like this can work – have you had chance to test such a solution? I’ll try implementing it tomorrow.

    Thread Starter skyer2000

    (@skyer2000)

    Maybe just throw <?php echo get_the_permalink(); ?> in there instead. I haven’t had a chance to test anything like this, so I’m just guessing what might work in that area!

    krmmalik

    (@krmmalik)

    So i tried PHP echo, but it doesnt look like i can execute any PHP code in the hook, i also have no previous PHP experience.

    I thought of another idea which was to use the javascript function “window.location.pathname” – I tested that with an alert function which worked fine, and i also concatenated the pathname and a string together to get a unique string for when the send button is pressed. That actually worked quite well, but when trying to apply the same for the trackPageview it fails and i suspect its because my syntax is incorrect, any ideas?

    on_sent_ok: "_gaq.push(['_trackPageview', window.location.pathname+'CallbackFormFilled']);"

    krmmalik

    (@krmmalik)

    I keep getting “_gaq is not defined” even if i store the pathname and concatenate the string into a variable first

    here’s an example:

    on_sent_ok: " var x=window.location.pathname+'CallbackFormFilled'; _gaq.push(['_trackPageview', x]);"'

    krmmalik

    (@krmmalik)

    I think i’ve solved it by doing the following

    on_sent_ok: " var x=window.location.pathname+'CallbackFormFilled';var _gaq = _gaq || [];_gaq.push(['_setAccount', 'UA-12632112-1']);_gaq.push(['_trackPageview', x]);"

    Seems to be working in terms of the form but i wont get stats till tomorrow

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Contact Form 7: Get Parameter from URL into Form Plugin’ is closed to new replies.