Skip to content

Instantly share code, notes, and snippets.

@deconf
Last active January 19, 2018 16:17
Show Gist options
  • Save deconf/db063aaea21974531c0bc42b502529a2 to your computer and use it in GitHub Desktop.
Save deconf/db063aaea21974531c0bc42b502529a2 to your computer and use it in GitHub Desktop.
Examples for GADWP v5 Tracking Code customization
<?php
/* Analytics Code */
function gadwp_addcode( $gadwp ) {
$commands = $gadwp->get(); // Get commands array
array_pop( $commands ); // Pop the last element
$fields = array();
$fields['hitType'] = 'pageview';
$commands[] = $gadwp->prepare( 'send', $fields ); // Add a new line to the commands array
$gadwp->set( $commands ); // Store the new commands array
}
add_action( 'gadwp_analytics_commands', 'gadwp_addcode', 10, 1 );
/* Tag Manager Datalayer */
function gadwp_adddatalayer( $gadwp ) {
$datalayer = $gadwp->get(); // Get DataLayer variables array
if ( $datalayer ){
array_pop( $datalayer ); // Pop the last variable
}
$gadwp->set( $datalayer ); // Store the new variables array
}
add_action( 'gadwp_tagmanager_datalayer', 'gadwp_adddatalayer', 10, 1 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment