skip to Main Content

does anyone here have any idea how to set up Site Tracking by passing a contact’s email address into Javascript Code?

I am on WordPress using the visual builder Elementor’s native contact form.

Here’s the contact form: https://www.bestseo.sg/free-report/ (Bottom of the page)

I have already inserted ActiveCampaign’s site tracking code sitewide.

However, it does not seem to start site tracking even after the form submission.

According to ActiveCampaign’s documentation(https://help.activecampaign.com/hc/en-us/articles/221542267-An-overview-of-Site-Tracking#how-to-pass-a-contact-s-email-address-into-javascript-code), I believe I have to add this line of code:

vgo('setEmail', 'Email_Address_Goes_Here');

above

vgo('process');

But I have no idea what to replace ‘Email_Address_Goes_Here’ with, in order to call the actual contact’s email after form submission.

Any help would be much appreciated!

Thank you.

2

Answers


  1. So the plugin used to insert these JavaScript codes is https://wordpress.org/plugins/header-and-footer-scripts/ – I’d suggest to maybe just keep using that, and keep the scripts in the footer, so that this does not require too much modication.

    Inside your template, you have to output the email addresse somewhere, where the JS can read it from – via a custom data attribute added to the body element for example.

    The header.php of your theme should contain something similar to

    <body <?php body_class(); ?>>
    

    Modify that, to add a custom data attribute to store the email address entered in the from:

    <body <?php body_class(); ?> data-freereportemail="<?php echo !empty($_POST['form_fields']['email']) ? esc_attr($_POST['form_fields']['email']) : ''; ?>">
    

    If the POST parameter by that name is set, then it will be output as content of this attribute, otherwise it’ll simply stay empty.

    Then modify the JavaScript code you insert via the plugin like this,

    var freereportemail = $('body').attr('data-freereportemail');
    if( freereportemail  != '' ) {
      vgo( 'setEmail', freereportemail );
    }
    

    This assumes that jQuery has already been loaded at this point, but I think that should most likely be the case.

    If the attribute contained an email address, then this will execute the vgo tracker function, if the attribute value is empty, then it will simply skip this call.

    This is not the most sophisticated approach, but it should do.

    (Only if you had other forms on the site as well, that use a form field of that exact same name, you might be tracking more than intended. In that case, you’d need to find some additional criterion, to be able to differentiate between these different forms.)

    Login or Signup to reply.
  2. A person at the AC support gave me thsi code :

    jQuery('form').submit(function() {
    var userEmail = jQuery("form input[type='email']").val();
    vgo('setEmail', userEmail);
    vgo('process');
    });
    

    I hope it’ll help you.

    I use FluentForms, so i just went on the form specific Custom JS/CSS to apply it (so i had no problems of proper targeting…)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search