forked from 40fingers/Dnn-Google-Tag-Manager-Connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleTagManagerEngine.cs
More file actions
72 lines (61 loc) · 2.23 KB
/
Copy pathGoogleTagManagerEngine.cs
File metadata and controls
72 lines (61 loc) · 2.23 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Services.Analytics
{
using System;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Services.Analytics.Config;
public class GoogleTagManagerEngine : AnalyticsEngineBase
{
public override string EngineName
{
get
{
return "GoogleTagManager";
}
}
public override string RenderScript(string scriptTemplate)
{
AnalyticsConfiguration config = this.GetConfig();
if (config == null)
{
return string.Empty;
}
var trackingId = string.Empty;
var urlParameter = string.Empty;
var trackForAdmin = true;
foreach (AnalyticsSetting setting in config.Settings)
{
switch (setting.SettingName.ToLowerInvariant())
{
case "gtmid":
trackingId = setting.SettingValue;
break;
case "trackforadmin":
if (!bool.TryParse(setting.SettingValue, out trackForAdmin))
{
trackForAdmin = true;
}
break;
}
}
if (string.IsNullOrEmpty(trackingId))
{
return string.Empty;
}
// check whether setting to not track traffic if current user is host user or website administrator.
if (!trackForAdmin &&
(UserController.Instance.GetCurrentUserInfo().IsSuperUser
||
(PortalSettings.Current != null &&
UserController.Instance.GetCurrentUserInfo().IsInRole(PortalSettings.Current.AdministratorRoleName))))
{
return string.Empty;
}
scriptTemplate = scriptTemplate.Replace("[GTM_ID]", trackingId);
return scriptTemplate;
}
}
}