Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@prasannakulkarni333
prasannakulkarni333 / Wordpress Data Layer Variables
Created September 24, 2017 19:07 — forked from BryanBarrera/Wordpress Data Layer Variables
Modified Wordpress datalayer variables for pulling: author names, post types, categories, page name, and dates into custom variables for the classic version of Google Analytics. Feel free to leave a comment or hit me up http://BryanBarrera.com
// Add this script after you make your dataLayer = []; call
// AND after your GTM code snippet
// This needs to go inside the header.php in order for it work globally across your site
<script type="text/javascript">
// URL toolbox - helps grabbing elements in the URL
var _d = document;
var _dl = _d.location;
var _dlp = _dl.pathname;
var _dls = _dl.search;
var _dr = _d.referrer;
function scrapeGoogle() {
var searchResults=UrlFetchApp.fetch("https://www.google.co.in/search?q="+encodeURIComponent("amarindaz youtube channel"));
var titleExp=/<h3 class=\"r\">([\s\S]*?)<\/h3>/gi;
var titleResults=searchResults.getContentText().match(titleExp);
// Logger.log(titleResults);
for(var i in titleResults)