Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
tannertechnology committed Feb 25, 2020
1 parent d5c90bb commit d98c315
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 38 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# GTM-for-YOURLS
Google Tag Manager for every single click

# Use
Simply open plugin.php and replace GTM-XXXXXX1 with your tagid

Copy to your plugins folder
76 changes: 38 additions & 38 deletions plugin.php → gtm-for-yourls/plugin.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
<?php
/*
Plugin Name: GoogleTagManager for YOURLS
Plugin URI: https://tanner.technology/GTM
Description: Adds google tag manager tracking to every clicked link
Version: 0.1
Author: Tanner Anderson
Author URI: https://tanner.technology/
*/

if( !defined( 'YOURLS_ABSPATH' ) ) die();

yourls_add_action( 'pre_redirect', 'gtm_add_tracking' );

function gtm_add_tracking( $args ) {
$url = $args[0];
$code = $args[1];
$tagid = "GTM-XXXXXX1"; // SET TAGID HERE

echo "<html>";
echo "<head>";
echo "<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','$tagid');</script>
<!-- End Google Tag Manager -->";
echo "</head>";

echo "<body>";
echo "<!-- Google Tag Manager (noscript) -->
<noscript><iframe src=\"https://www.googletagmanager.com/ns.html?id=$tagid\"
height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->";
echo "<p>Please <a href='$url'>click here</a> if you are not automatically redirected.</p>";
echo "</body>";
echo "</html>";
<?php
/*
Plugin Name: GoogleTagManager for YOURLS
Plugin URI: https://tanner.technology/GTM
Description: Adds google tag manager tracking to every clicked link
Version: 1
Author: Tanner Anderson
Author URI: https://tanner.technology/
*/

if( !defined( 'YOURLS_ABSPATH' ) ) die();

yourls_add_action( 'pre_redirect', 'gtm_add_tracking' );

function gtm_add_tracking( $args ) {
$url = $args[0];
$code = $args[1];
$tagid = "GTM-XXXXXX1"; // SET TAGID HERE

echo "<html>";
echo "<head>";
echo "<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','$tagid');</script>
<!-- End Google Tag Manager -->";
echo "</head>";

echo "<body>";
echo "<!-- Google Tag Manager (noscript) -->
<noscript><iframe src=\"https://www.googletagmanager.com/ns.html?id=$tagid\"
height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->";
echo "<p>Please <a href='$url'>click here</a> if you are not automatically redirected.</p>";
echo "</body>";
echo "</html>";
}

0 comments on commit d98c315

Please sign in to comment.