Skip to content

Instantly share code, notes, and snippets.

@cspenn
Last active November 14, 2021 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cspenn/b3181132c44d4b4dd1074d0275345222 to your computer and use it in GitHub Desktop.
Save cspenn/b3181132c44d4b4dd1074d0275345222 to your computer and use it in GitHub Desktop.
Instagram Linktree Substitute with Google Analytics
<?
/*********************************
Instagram Linktree substitute w/GA integration
Inspired by Glenn Walker's PHP-UA
Christopher S. Penn
https://www.christopherspenn.com/
https://www.trustinsights.ai
Provided under the GNU Public License with absolutely no warranty or support.
I recommend you place this in a folder in your root domain called /instagram and then change the link in your Instagam bio to whatever your website is plus instagram - for example, https://www.christopherspenn.com/instagram
Requires PHP 5.6 or better.
**********************************/
// Configuration - edit these parts!
// Where are we sending people from Instagram?
$destination = "https://www.christopherspenn.com/";
// Insert your UTM codes here!
$source = "instagram"; // utm_source
$medium = "social"; // utm_medium
$campaign = "biolink"; // utm_campaign
// Insert your Google Analytics account ID here, beginning with UA-
$analyticsua = "UA-336872-14";
/*********************************
// Don't edit past here
**********************************/
$curlurl = "https://www.google-analytics.com/collect?v=1&tid=".$analyticsua."&cid=".$guid."&t=pageview&cs=".$source."&cm=".$medium."&cn=".$campaign;
$finalurl = "Location: ".$destination."?utm_source=".$source."&utm_medium=".$medium."&utm_campaign=".$campaign;
$guid = microtime();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $curlurl,
CURLOPT_USERAGENT => "Instagram-Bio-Link-Tracker",
));
$resp = curl_exec($curl);
curl_close($curl);
header("HTTP/1.1 301 Moved Permanently");
header($finalurl);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment