Skip to content

Commit 74b7f79

Browse files
msohailhussainmikeproeng37
authored andcommitted
Feature - Anonymize IP (#21)
1 parent 6bfa849 commit 74b7f79

File tree

5 files changed

+29
-14
lines changed

5 files changed

+29
-14
lines changed

OptimizelySDK.Tests/EventTests/EventBuilderTest.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public void TestCreateImpressionEventNoAttributes()
7575
{"account_id", "1592310167" },
7676
{"client_name", "csharp-sdk" },
7777
{"client_version", "1.2.0" },
78-
{"revision", 15 }
78+
{"revision", 15 },
79+
{"anonymize_ip", false}
7980
};
8081

8182
var expectedLogEvent = new LogEvent("https://logx.optimizely.com/v1/events",
@@ -153,7 +154,8 @@ public void TestCreateImpressionEventWithAttributes()
153154
{"account_id", "1592310167" },
154155
{"client_name", "csharp-sdk" },
155156
{"client_version", "1.2.0" },
156-
{"revision", 15 }
157+
{"revision", 15 },
158+
{"anonymize_ip", false}
157159
};
158160

159161
var expectedLogEvent = new LogEvent("https://logx.optimizely.com/v1/events",
@@ -226,8 +228,9 @@ public void TestCreateConversionEventNoAttributesNoValue()
226228
{"project_id", "7720880029"},
227229
{"account_id", "1592310167"},
228230
{"client_name", "csharp-sdk"},
229-
{"client_version", "1.2.0"},
230-
{"revision", 15}
231+
{"client_version", "1.2.0" },
232+
{"revision", 15 },
233+
{"anonymize_ip", false}
231234
};
232235

233236
var expectedEvent = new LogEvent(
@@ -304,8 +307,9 @@ public void TestCreateConversionEventWithAttributesNoValue()
304307
{"project_id", "7720880029"},
305308
{"account_id", "1592310167"},
306309
{"client_name", "csharp-sdk"},
307-
{"client_version", "1.2.0"},
308-
{"revision", 15}
310+
{"client_version", "1.2.0" },
311+
{"revision", 15 },
312+
{"anonymize_ip", false}
309313
};
310314

311315
var expectedEvent = new LogEvent(
@@ -386,7 +390,8 @@ public void TestCreateConversionEventNoAttributesWithValue()
386390
{"account_id", "1592310167" },
387391
{"client_name", "csharp-sdk" },
388392
{"client_version", "1.2.0" },
389-
{"revision", 15 }
393+
{"revision", 15 },
394+
{"anonymize_ip", false}
390395
};
391396

392397
var expectedEvent = new LogEvent(
@@ -477,7 +482,8 @@ public void TestCreateConversionEventWithAttributesWithValue()
477482
{"account_id", "1592310167" },
478483
{"client_name", "csharp-sdk" },
479484
{"client_version", "1.2.0" },
480-
{"revision", 15 }
485+
{"revision", 15 },
486+
{"anonymize_ip", false}
481487
};
482488

483489
var expectedEvent = new LogEvent(
@@ -563,7 +569,8 @@ public void TestCreateConversionEventNoAttributesWithInvalidValue()
563569
{"account_id", "1592310167" },
564570
{"client_name", "csharp-sdk" },
565571
{"client_version", "1.2.0" },
566-
{"revision", 15 }
572+
{"revision", 15 },
573+
{"anonymize_ip", false}
567574
};
568575

569576
var expectedEvent = new LogEvent(
@@ -645,7 +652,8 @@ public void TestConversionEventWithNumericTag()
645652
{"account_id", "1592310167" },
646653
{"client_name", "csharp-sdk" },
647654
{"client_version", "1.2.0" },
648-
{"revision", 15 }
655+
{"revision", 15 },
656+
{"anonymize_ip", false}
649657
};
650658

651659
var expectedEvent = new LogEvent(

OptimizelySDK.Tests/TestData.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,6 @@
159159
"key": "purchase"
160160
}
161161
],
162-
"revision": "15"
162+
"revision": "15",
163+
"anonymizeIP": "false"
163164
}

OptimizelySDK/Event/Builder/EventBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class EventBuilder
4949

5050
public EventBuilder(Bucketer bucketer)
5151
{
52-
Bucketer = bucketer;
52+
Bucketer = bucketer;
5353
ResetParams();
5454
}
5555

@@ -95,7 +95,7 @@ private Dictionary<string, object> GetCommonParams(ProjectConfig config, string
9595
comonParams[Params.CLIENT_ENGINE] = SDK_TYPE;
9696
comonParams[Params.CLIENT_VERSION] = SDK_VERSION;
9797
comonParams[Params.REVISION] = config.Revision;
98-
98+
comonParams[Params.ANONYMIZE_IP] = config.AnonymizeIP;
9999

100100
var userFeatures = new List<Dictionary<string, object>>();
101101

@@ -272,4 +272,4 @@ public virtual LogEvent CreateConversionEvent(ProjectConfig config, string event
272272
return new LogEvent(CONVERSION_ENDPOINT, conversionParams, HTTP_VERB, HTTP_HEADERS);
273273
}
274274
}
275-
}
275+
}

OptimizelySDK/Event/Builder/Params.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ public static class Params
3838
public const string CLIENT_ENGINE = "client_name";
3939
public const string CLIENT_VERSION = "client_version";
4040
public const string IS_LAYER_HOLDBACK = "isLayerHoldback";
41+
public const string ANONYMIZE_IP = "anonymize_ip";
4142
}
4243
}

OptimizelySDK/ProjectConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public class ProjectConfig
4848
/// </summary>
4949
public int Revision { get; set; }
5050

51+
/// <summary>
52+
/// Allow Anonymize IP by truncating the last block of visitors' IP address.
53+
/// </summary>
54+
public bool AnonymizeIP { get; set; }
55+
5156
//========================= Mappings ===========================
5257

5358
/// <summary>

0 commit comments

Comments
 (0)