-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrations.cs
More file actions
79 lines (64 loc) · 3.18 KB
/
Migrations.cs
File metadata and controls
79 lines (64 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Commercan.GoogleAnalytics.Models;
using Orchard.Data;
using Orchard.Data.Migration;
using Orchard.Data.Migration.Schema;
namespace Commercan.GoogleAnalytics {
public class Migrations : DataMigrationImpl {
private readonly IRepository<ScriptCodesRecord> _repository;
public Migrations(IRepository<ScriptCodesRecord> repository) {
_repository = repository;
}
public int Create() {
SchemaBuilder.CreateTable("SettingsRecord",
table => table.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<bool>("Enable", column => column.NotNull().WithDefault(false))
.Column<bool>("UseUniversalTracking", column => column.NotNull().WithDefault(false))
.Column<string>("GoogleAnalyticsKey"));
SchemaBuilder.CreateTable("ScriptCodesRecord",
table => table.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("ScriptType", column => column.NotNull().WithLength(50))
.Column<string>("Script", column => column.NotNull().Unlimited()));
InsertUniversalAnalyticsScript();
InsertGAScript();
return 1;
}
private void InsertUniversalAnalyticsScript() {
var script = new ScriptCodesRecord {
ScriptType = "universal",
Script = @"<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){{i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){{
(i[r].q=i[r].q||[]).push(arguments)}},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
}})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '{0}', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->"
};
_repository.Create(script);
}
private void InsertGAScript()
{
var script = new ScriptCodesRecord
{
ScriptType = "ga",
Script = @"<script type=""text/javascript"">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{0}']);
_gaq.push(['_trackPageview']);
(function() {{
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}})();
</script>"
};
_repository.Create(script);
}
}
}