Skip to content

Commit

Permalink
Add more different types of self-describing event (close #76)
Browse files Browse the repository at this point in the history
  • Loading branch information
istreeter committed Jan 23, 2024
1 parent a340647 commit 970de2b
Show file tree
Hide file tree
Showing 35 changed files with 1,037 additions and 26 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ Aside from "output" configuration, all fields in the configuration file are opti
"unstruct": 1
"pageView": 1
"pagePing": 1
"unstructEventFrequencyDefault": 1
"unstructEventFrequencies": {
"changeForm": 1
"funnelInteraction": 1
"linkClick": 1
"change_form": 10
"funnel_interaction": 100
"link_click": 1000
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object Body {
u <- User.genOpt
event <- e match {
case EventType.Struct => StructEvent.gen
case EventType.Unstruct => UnstructEventWrapper.gen(now, frequencies.unstructEventFrequencies)
case EventType.Unstruct => UnstructEventWrapper.gen(now, frequencies)
case EventType.PageView => PageView.gen
case EventType.PagePing => PagePing.gen
case EventType.Transaction => TransactionEvent.gen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ case class EventFrequencies(
pagePing: Int,
transaction: Int,
transactionItem: Int,
unstructEventFrequencies: UnstructEventFrequencies
unstructEventFrequencyDefault: Int,
unstructEventFrequencies: Map[String, Int]
)

sealed trait EventType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.event

import com.snowplowanalytics.snowplow.eventgen.protocol.unstructs.{ChangeForm, FunnelInteraction, LinkClick}
import com.snowplowanalytics.snowplow.eventgen.protocol.unstructs.AllUnstructs
import com.snowplowanalytics.iglu.core.SelfDescribingData
import com.snowplowanalytics.snowplow.analytics.scalasdk.SnowplowEvent
import com.snowplowanalytics.snowplow.eventgen.primitives.base64Encode
Expand All @@ -22,8 +22,6 @@ import org.apache.http.message.BasicNameValuePair
import org.scalacheck.Gen
import java.time.Instant

case class UnstructEventFrequencies(changeForm: Int, funnelInteraction: Int, linkClick: Int)

final case class UnstructEventWrapper(
event: SelfDescribingData[Json],
b64: Boolean
Expand All @@ -38,12 +36,17 @@ final case class UnstructEventWrapper(
}

object UnstructEventWrapper {
def gen(now: Instant, frequencies: UnstructEventFrequencies): Gen[UnstructEventWrapper] =
Gen
.frequency(
frequencies.linkClick -> LinkClick.gen(now),
frequencies.changeForm -> ChangeForm.gen(now),
frequencies.funnelInteraction -> FunnelInteraction.gen(now)
)
.map(l => UnstructEventWrapper(l, b64 = true))

def gen(now: Instant, config: EventFrequencies): Gen[UnstructEventWrapper] = {
val freqToUnstruct = AllUnstructs.all.map { unstruct =>
val frequency =
config
.unstructEventFrequencies
.getOrElse(unstruct.schemaKey.name, default = config.unstructEventFrequencyDefault)

frequency -> unstruct.gen(now)
}
Gen.frequency(freqToUnstruct: _*).map(l => UnstructEventWrapper(l, b64 = true))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdBreakEndEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_break_end_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map.empty

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdBreakStartEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_break_start_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map.empty

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdClickEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_click_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map.empty

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdCompleteEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_complete_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map.empty

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import com.snowplowanalytics.snowplow.eventgen.protocol.implicits._
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdPauseEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_pause_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map(
"percentProgress" -> Gen.chooseNum(0, 100).optionalOrNull
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import com.snowplowanalytics.snowplow.eventgen.protocol.implicits._
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdQuartileEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_quartile_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map(
"percentProgress" -> Gen.chooseNum(0, 100).required
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import com.snowplowanalytics.snowplow.eventgen.protocol.implicits._
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdResumeEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_resume_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map(
"percentProgress" -> Gen.chooseNum(0, 100).optionalOrNull
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import com.snowplowanalytics.snowplow.eventgen.protocol.implicits._
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdSkipEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_skip_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map(
"percentProgress" -> Gen.chooseNum(0, 100).optionalOrNull
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021-2022 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.eventgen.protocol.unstructs

import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer}
import com.snowplowanalytics.snowplow.eventgen.protocol.SelfDescribingJsonGen
import org.scalacheck.Gen
import io.circe.Json
import java.time.Instant

object AdStartEvent extends SelfDescribingJsonGen {

override def schemaKey: SchemaKey =
SchemaKey("com.snowplowanalytics.snowplow.media", "ad_start_event", "jsonschema", SchemaVer.Full(1, 0, 0))

override def fieldGens(now: Instant): Map[String, Gen[Option[Json]]] =
Map.empty

}
Loading

0 comments on commit 970de2b

Please sign in to comment.