Skip to content

Instantly share code, notes, and snippets.

@latestscoop
Last active June 20, 2018 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save latestscoop/444a586c508725ecd2cea73ed56af4f1 to your computer and use it in GitHub Desktop.
Save latestscoop/444a586c508725ecd2cea73ed56af4f1 to your computer and use it in GitHub Desktop.
PHP: On success inject JavaScript to redirect to another page (+ pass url parameter)
<?php
//pass a value to url parameter called param
$value = 'value';
//on success (eg: form sent) $var='trigger'
if ($var=='trigger'){
//redirect to url after 2 seconds
echo '<script type="text/JavaScript">' . 'setTimeout("location.href =' . " 'http://www.example.com/?param=" . $value . "';" . '",2000);' . '</script>' ;
}
?>
@latestscoop
Copy link
Author

Create a Google Analytics Goal with regex to pick up the URL parameter and value, select; Admin > Account > Property > Goals
Regular expression examples: https://gist.github.com/latestscoop/7eb4e5c216230bebe209e9aaa16c4894

Import the goal to Google AdWords as a completion metric, select; Tools > Measurement > Conversions > Add > Import (from GA)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment