Tracking embedded and dynamically loaded YouTube videos via Google Tag Manager

Tracking YouTube videos in Google Analytics via Google Tag Manager is not a trivial thing. Previously, I have been using the method proposed by CardinalPath and it works pretty well for most people. However, I needed a bit more flexibility; e.g. I need to track not only embedded videos but also videos loaded dynamically. This could be videos loaded in a lightbox popup. In my case, videos loaded via the Magnific Popup script.

Read more

Nodes disappearing from internal cache in Umbraco

Occasionally some of the sites I have made in Umbraco 4 have pages that are for some reason not in the internal cache. The solution is to run the following command while logged in to Umbraco:

http://www.example.com/umbraco/dialogs/republish.aspx?xml=true

This will republish all pages and put them back into the cache. It can take quite a while if it is a large site.

Read more

Prevent reload with BrowserSync and Laravel

I use BrowserSync with Laravel Elixir and I found that when I use cache busting it reloads the page instead of injecting the CSS into it. This is of course due to the way cache busting works. Still, this is quite annoying. However, there is a really simple solution to the issue. In your master blade template just make a check to see if you are on a local environment like so:

@if (app()->isLocal())
    <link rel="stylesheet" type="text/css" href="{{ asset('css/app.css') }}">
@else
    <link rel="stylesheet" type="text/css" href="{{ elixir('css/app.css') }}">
@endif

This is half the solution.

Read more

Remove node_modules folder on Windows without errors

I sometimes get errors when I run npm install for my Gulp or Grunt projects. To retry I need to remove the node_modules folder and sometimes that causes problems as when you are on Windows. I had a look around and found a Git repository named rimraf.

To remove a node_modules folder on your system, first install rimraf globally

npm install rimraf -g

Then, navigate to the folder just above the folder you want to remove and run

rimraf node_modules

…and the node_modules folder will be removed.

Read more

Create additional databases in Laravel Homestead

It is really easy to ad more databases in Laravel Homested. Simply edit the Homestead.yaml file (in Windows under C:Usersyour-username.homesteadHomestead.yaml)

Under databases add your databases like this:

# content above omitted

databases:
    - homestead
    - my_new_database
    - another_database

# content below omitted

If you virtual machine is already running navigate to your Homestead folder and run the command vagrant provision to create the new database(s). If it is not running simply run vagrant up.

Read more

Solution to MySQL error “Error establishing a database connection” in WordPress on DigitalOcean

I’m hosting my sites with DigitalOcean (referral link) on the smallest VPS with 512 MB Ram. It’s a cheap way of hosting as I can have virtually as many sites I want on the VPS – and in case it is too slow I can easily upgrade it from the control panel. However, I occasionally get an error on my WordPress sites saying  “Error establishing a database connection”. I searched around for a solution and finally found that I needed to add a swap file to the server.

Read more