Skip to content

Commit

Permalink
Link to the pro
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Jul 22, 2020
1 parent a9f1f1e commit d925e91
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 42 deletions.
118 changes: 77 additions & 41 deletions assets/js/controls.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
/* eslint camelcase: warn */

( function( $ ) {
if ( ! window.cf7_extras ) {
return;
}

var jQueryEvent, formEventCallback;

var formEventCallbacks = {
wpcf7mailsent: function( form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Sent', formConfig.title );
}
},
wpcf7mailfailed: function( form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Error', formConfig.title );
}
},
wpcf7spam: function( form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Spam', formConfig.title );
}
},
wpcf7submit: function( form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Submit', formConfig.title );
}

if ( form.contactFormId && 'mail_sent' === form.status && formEventEnabled( form.contactFormId, 'redirect-success' ) ) {
formConfig = getFormConfig( form.contactFormId );

if ( formConfig.redirect_url ) {
window.location = formConfig.redirect_url;
}
}
}
};

var jQueryEvents = {
'wpcf7:mailsent': function( event, form ) {
formCallbacks.wpcf7mailsent( form );
},
'wpcf7:mailfailed': function( event, form ) {
formCallbacks.wpcf7mailfailed( form );
},
'wpcf7:spam': function( event, form ) {
formCallbacks.wpcf7spam( form );
},
'wpcf7:submit': function( event, form ) {
formCallbacks.wpcf7submit( form );
}
};

function trackAnalyticsEvent( eventCategory, eventAction, eventTitle ) {

Expand Down Expand Up @@ -64,47 +121,26 @@
return false;
};

$( document ).on( 'wpcf7:mailsent', function( event, form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Sent', formConfig.title );
}
} );

$( document ).on( 'wpcf7:mailfailed', function( event, form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Error', formConfig.title );
}
} );

$( document ).on( 'wpcf7:spam', function( event, form ) {
var formConfig;
// We need the event config for each form to do anything.
if ( ! window.cf7_extras ) {
return;
}

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Spam', formConfig.title );
// Register the new JS events in CF7 version 5.2 and above.
if ( 'function' === typeof document.addEventListener ) {
for ( formEventCallback in formEventCallbacks ) {
document.addEventListener( formEventCallback, function( event ) {
if ( event.detail ) {
formEventCallbacks[ formEventCallback ].call( this, event.detail );
}
} );
}
} );

$( document ).on( 'wpcf7:submit', function( event, form ) {
var formConfig;

if ( form.contactFormId && formEventEnabled( form.contactFormId, 'track-ga' ) ) {
formConfig = getFormConfig( form.contactFormId );
trackAnalyticsEvent( 'Contact Form', 'Submit', formConfig.title );
// Register the legacy jQuery events pre CF7 version 5.2.
} else if ( 'function' === typeof $ ) {
for ( jQueryEvent in jQueryEvents ) {
$( document ).on( jQueryEvent, jQueryEvents[ jQueryEvent ] );
}
}

if ( form.contactFormId && 'mail_sent' === form.status && formEventEnabled( form.contactFormId, 'redirect-success' ) ) {
formConfig = getFormConfig( form.contactFormId );

if ( formConfig.redirect_url ) {
window.location = formConfig.redirect_url;
}
}
} );
}( jQuery ) );
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: Controls for Contact Form 7
* Description: Simple controls for the advanced functionality of Contact Form 7.
* Description: Simple controls for the advanced functionality of Contact Form 7. Pre-order the <a href="https://formcontrols.com/pro">🚀 PRO version</a> for advanced analytics and tracking features.
* Plugin URI: https://formcontrols.com
* Author: Kaspars Dambis
* Author URI: https://formcontrols.com
Expand Down

0 comments on commit d925e91

Please sign in to comment.