Last active
January 19, 2018 16:17
-
-
Save deconf/db063aaea21974531c0bc42b502529a2 to your computer and use it in GitHub Desktop.
Examples for GADWP v5 Tracking Code customization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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