Skip to content

Instantly share code, notes, and snippets.

@SearchStar
SearchStar / Measuring Views of Product Details
Last active August 29, 2015 14:08
Enhanced Ecommerce tracking with GTM
Overview
Google Analytics Enhanced Ecommerce enables product impression, promotion, and sales data to be sent with any of your Google Analytics pageviews and events.
You should review the Enhanced Ecommerce Data Types and Actions section of the Enhanced Ecommerce Dev Guide before you begin. The guide will help you understand which fields are required for each of the ecommerce interactions you want to measure.
https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
The Ecommerce Process
<?php
$transactionId='test1001';
$sku=array('test1003','test1001','test1002');
$name=array('six1','six2','six3');
$category=array('142139113','161477257','574557754');
$price=array(53.90,9.99,36.36);
$quantity=array(1.00,1.00,1.00);
$transactionAffiliation='affil';
$transactionTotal='100.25';
<script type="text/javascript">
var orderId = '12345';
var OrderTotal = 100.25;
var attraction = 'new';
var ShippingCity = 'wilts';
var ShippingCountyState = 'london';
var ShippingCountry = 'england';
var ShippingMethod = 3.99;
var OrderTax = 11.99;
var ItemSKU = ["1234567890", "0987654321", "123456789012"];
@SearchStar
SearchStar / Add Vimeo API Params Tag.html
Last active August 11, 2023 08:07
Vimeo video tracking with Google Tag Manager
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var vimeoTag = document.getElementsByTagName('iframe');
for(i=0; i<vimeoTag.length; i++){
var newSrc = vimeoTag[i].src + '?api=1&player_id=player_' + i;
vimeoTag[i].id = 'player_' + i;
vimeoTag[i].src = newSrc;
}
@SearchStar
SearchStar / Form.html
Last active January 4, 2024 14:25
Instructions for adding Google AdWords GCLID tracking for the Conversion Upload tool
/* 2. Modify your site’s prospect lead information submission page — usually, a lead submission form — to read the
* GCLID from the cookie and pass it along to your lead management system, along with the lead’s contact information.
* You can retrieve the GCLID value via your choice of client- or server-side languages. Once retrieved, it’s a good
* idea to pass the GCLID through your lead submission form as a hidden field element.
* Here’s an example form with a hidden field for collecting the GCLID. You should insert the highlighted <input>
*/ tag in between your <form> tags.:
<form action="" name="myForm">
Name: <input type="text" name="name">
<input type="hidden" id="gclid" name="gclid" value="">
@SearchStar
SearchStar / AdWords Call Tracking.js
Last active August 29, 2015 14:07
AdWords Call Tracking using a CSS Class selector
// https://support.google.com/adwords/answer/1722054?hl=en-GB#calls_from_websites
<script>
(function(a,e,c,f,g,b,d){var h={ak:"1068572616",cl:"J3467990UQyL577QM"};a[c]=a[c]||function(){(a[c].q=a[c].q||[]).push(arguments)};a[f]||(a[f]=h.ak);b=e.createElement(g);b.async=1;b.src="//www.gstatic.com/wcm/loader.js";d=e.getElementsByTagName(g)[0];d.parentNode.insertBefore(b,d);a._googWcmGet=function(b,d,e){a[c](2,b,h,d,null,new Date,e)}})(window,document,"_googWcmImpl","_googWcmAk","script");
</script>
<body onload="_googWcmGet('phone-number', '01225 746 967')">
<span class="phone-number">01225 746 967</span>
@SearchStar
SearchStar / Eccommerce Event Tracking.js
Last active August 29, 2015 14:07
Push ecommerce data into a data layer array using JavaScript
<script type="text/javascript">
var cartProducts = [];
var dataLayer = [];
for(var i=0; i<x; i++){
cartProducts.push({
'id': transactionId,
'sku': sku[i], // string; product ID
'name': name[i], // string; product name
'category': category[i], // string; category name
@SearchStar
SearchStar / PHP Eccommerce Tracking.php
Last active May 9, 2021 23:08
Implementing a Google Tag Manager ecommerce data layer with PHP
<?php
$transactionId='test1001';
$sku=array('test1003','test1001','test1002');
$name=array('six1','six2','six3');
$category=array('142139113','161477257','574557754');
$price=array(53.90,9.99,36.36);
$quantity=array(1.00,1.00,1.00);
$transactionAffiliation='affil';
@SearchStar
SearchStar / footer.js
Last active August 29, 2015 14:07
Loads Google Tag Manager code snippet and data layer from an external .js file